Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJohnny Harrison
4,331 PointsCan we reuse the 'guess' variable?
In my program, I just had the conditional statement overwrite the 'guess' variable instead of making new 'guessLess' and 'guessMore' variables. Is there anything wrong with this approach?
1 Answer
Stamos Bolovinos
4,320 PointsHi Johnny
I think I can answer this question, although I'm quite new to JavaScript, but I do have scripting experience in contact center routing strategies.
Overwriting a variable, if you don't need to keep track of the old value, is very common. A variable can get overwritten many times while a script runs.
The only reason I can think of for using more than one variable in this case, is if you wanted to add reporting at the end and display the two guesses to the user. But even in this case, two variables would do the job (e.g. guessSecond
).
Dayana Guevara
Courses Plus Student 2,008 PointsDayana Guevara
Courses Plus Student 2,008 PointsThat is what I did also! It seems to work too.