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 trialNiall Maher
16,985 PointsCan't get my javascript to show up in my html file when I view it.
Can anyone help show me where I'm going wrong. I've ran it with a few different ways and still nothing. Frustrating as you can imagine.
Thanks :)
Here's my code:
var upper = 10000; var randomNumber = getRandomNumber(upper); var = guess; var = attempts;
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 " + randomNumber + "</p>") document.write("<p>It took " + attempts + " to guess right</p>")
1 Answer
Marcus Parsons
15,719 PointsHey Niall,
When you're making new variables, you only need to put var attempts
instead of var = attempts
and the same for the guess variable. Just remove the equals from the very top where you create the variables. But, for attempts, since you are adding 1 to it, I would create it as var attempts = 0;
so that there is a starting point for attempts.
Also, in your first document.write(), you can put a period and a space in the empty string so that it looks nice on the page and you should put semi-colons on the end of your commands:
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("The random number was " + randomNumber + ". ");
document.write("It took " + attempts + " to guess right");
Niall Maher
16,985 PointsThanks brother I had just figured it out but I really appreciate the fast response :)
Marcus Parsons
15,719 PointsOh awesome man! haha I see your comment now. You gotta love Chrome's features. Happy Coding! :)
Niall Maher
16,985 PointsNiall Maher
16,985 PointsHad a coffee and as we all no programmers + coffee = results :P
I had "=" symbols after declaring variable "guess" and "attempts" Thanks Chrome debugger :P