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 trial

JavaScript JavaScript Loops, Arrays and Objects Simplify Repetitive Tasks with Loops A Closer Look at Loop Conditions

Ozgur Parlakkilic
Ozgur Parlakkilic
8,399 Points

I dont see what I am doing wrong, code wont run

pls let me know if its my browser, because I went over this line by line and its the same thing.

var upper = 10000;
var randomNumber = getRandomNumber(upper);
var guess;
var attempts = 0;

function getRandomNumber(upper) {
  return Math.floor( Math.random() * upper ) + 1;
}

while (guess !== randomNumber) {
  guess = getRandomNumber(upper);
  attempts += 1;
}
document.write("<p>The random number was: " + randomNuber + "</p>");
document.write("<p>It took the computer" + attempts + " attempts to get it right.</p>");

Moderator Edit: Added Markdown to the code snippet so that it is readable in the Community. Please refer to the Markdown Cheatsheet when posting code to the forums for proper Markdown formatting.

3 Answers

andren
andren
28,558 Points

You have a typo in your first document.write command. You type randomNuber instead of randomNumber.

If you fix that typo then your code will run.

I advise you to debug your code by using the Chrome console like Dave is doing on videos. Then, It will take a second to find bugs like yours.

Ozgur Parlakkilic
Ozgur Parlakkilic
8,399 Points

Thank you so much, I saw it after I took a 10-minute break. I guess sometimes you just need to take a break to see mistakes, but I greatly appreciate it