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 trialRan Wang
Full Stack JavaScript Techdegree Graduate 32,191 PointsReplace the "guess" in the while condition with the call of function?
Other parts being the same, why my browser ran into endless loop when I replace the 'guess' with getRandomNumber(upper)'?
˜˜˜ while (getRandomNumber(upper) !== randomNumber) { getRandomNumber(upper); attemps += 1; }
˜˜˜ my idea is to call the function and it will each time return a value, if this value does not equal to the randomNumber, then call the function to run again in the loop.
For me, the above code seems logical, but the browser told me no.
3 Answers
Steven Parker
231,268 PointsIt would help to see your whole code, this part doesn't look like it would cause your issue.
But you can remove the 2nd call to "getRandomNumber", it doesn't really do anything now that "guess" has been removed except slow things down.
If you still have an issue please post the complete code. And the three marks that would indicate code for formatting are accents ("back-ticks").
Ran Wang
Full Stack JavaScript Techdegree Graduate 32,191 Pointstest
print ("hello world");
Steven Parker
231,268 PointsFYI: You can get syntax coloring if you add "js" to the first set of ticks. ```js
Jeff Sanders
Courses Plus Student 9,503 PointsThere are in fact some major problems with this code.
- your var guess does nothing
- the GetRandomNumber call within the while loop is unnecessary because you aren't storing that value anywhere
- you aren't storing the computer's guess anywhere, so the program is very limited. For example, you couldn't analyze each guess if that became a requirement later on down the line
Ran Wang
Full Stack JavaScript Techdegree Graduate 32,191 PointsRan Wang
Full Stack JavaScript Techdegree Graduate 32,191 Pointsthank you for your help, my whole code is as follows:
Steven Parker
231,268 PointsSteven Parker
231,268 PointsI still don't see anything wrong. When I tried the code, I got this response:
Removing the redundant call speeds it up but doesn't affect the final result.
Ran Wang
Full Stack JavaScript Techdegree Graduate 32,191 PointsRan Wang
Full Stack JavaScript Techdegree Graduate 32,191 PointsThank you for the help with the code and the post-coloring tops XD !