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 trialJosh Prakke
4,412 PointsMy take on the random number generator using conditional statements.
Hey guys I've been going through these courses without any outside input. How does my code look? Is there anything I'm missing with formatting issues etc?
console.log("Program Begins");
var randomNumber = Math.floor(Math.random() * 6 ) + 1;
console.log(randomNumber);
var guess= prompt("I am thinking of a number between one and six can you guess it?");
if (randomNumber === parseInt(guess)) {
alert("You got it! Are you sure you weren't cheating?");
} else {
alert("Ahh, better luck next time! The number was " + randomNumber + ".");
}
var retry = prompt("Would you like to try again?")
var retryCaps = retry.toUpperCase();
if (retryCaps === "YES") {
location.reload();
} else {
alert("Okay, thanks for playing!");
}
console.log("Program Ends");
Josh Prakke
4,412 PointsSharay Brown , awesome thanks for taking the time to look through it. I can definitely say grammar isn't my strongest skill thanks for lookin out!
1 Answer
Tyler Corum
3,514 PointsI recommend you remove the variable creation of retryCaps and simply say if (retry.toUpperCase() === "YES") {...}
You could also use a do while loop to encapsulate the entire thing. I'm sure you're beyond this by now, though. Keep up the efforts. You'll need to study grammar more. It's important.
Sharay Brown
11,900 PointsSharay Brown
11,900 PointsI tested the code and it works great. It was also easy to read and understand. Just a small fix for the user: var guess= prompt("I am thinking of a number between one and six. Can you guess it?");