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 Basics (Retired) Making Decisions with Conditional Statements Booleans

Ryan B.
Ryan B.
3,236 Points

Where am i going wrong?

Bummer! Did you add true inside the parentheses of the conditional statement?

script.js
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');
}
index.html
<!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
Piotrek Smyda
3,786 Points

Hi, 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.
Ryan B.
3,236 Points

I haven't been introduced to loops as of yet but it doesn't hurt to give it a try.

Piotrek Smyda
Piotrek Smyda
3,786 Points

ahh ok. can you tell me at which stage you are right now?

Ryan B.
Ryan B.
3,236 Points

I was just introduced to Conditional Statements and Booleans.

Ryan B.
Ryan B.
3,236 Points

I 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
Piotrek Smyda
3,786 Points

Ok 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
Piotrek Smyda
3,786 Points

Great! Congrats:) Sorry for my slow answers.

Good luck on the JS Course.