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 trialRyan B.
3,236 PointsWhere am i going wrong?
Bummer! Did you add true
inside the parentheses of the conditional statement?
var correctGuess=true;
var randomNumber=Math.floor(Math.random()*6) + 1;
var guess=prompt('I am thinking of a number, what is it?');
if (parseInt(guess)===randomNumber) {
alert('This is true');
} else {
alert('This is false');
}
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JavaScript Basics</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
1 Answer
Piotrek Smyda
3,786 PointsHi, I think you've misunderstood the challenge.
You need to create loop that will run until you would guess the number. I think it should be something like this:
while (true) {
if ( parseInt(guess) === randomNumber) {
}
}
I hope this will set you on track.
Ryan B.
3,236 PointsRyan B.
3,236 PointsI haven't been introduced to loops as of yet but it doesn't hurt to give it a try.
Piotrek Smyda
3,786 PointsPiotrek Smyda
3,786 Pointsahh ok. can you tell me at which stage you are right now?
Ryan B.
3,236 PointsRyan B.
3,236 PointsI was just introduced to Conditional Statements and Booleans.
Ryan B.
3,236 PointsRyan B.
3,236 PointsI figured it out. I made it more difficult than it needed to be. Where I used the 'parseInt' all i needed to do was add the word true in parentheses. Sorry for the inconvenience. Appreciate your help.
Piotrek Smyda
3,786 PointsPiotrek Smyda
3,786 PointsOk I've found that challenge.
You're doing too much there. This challenge is just to show you how the if statement works.
The solution was presented in the first example of preceding video. Just type "true" inside parentheses and you will be fine.
Piotrek Smyda
3,786 PointsPiotrek Smyda
3,786 PointsGreat! Congrats:) Sorry for my slow answers.
Good luck on the JS Course.