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 trialTlaleng Ramoroke
1,627 Pointshelp debugging and making my program work as expected
not sure why my code doesn't work as expected .I do get the error however I tried to correct but with bo success .here is my code ,please check it out and tell me what I am getting wrong.and now I don't see where to add the screenshot of my code.i am daily new ,please help with that too. ...javascript <p>var randomNumber = getRandomNumber(10); var guess; var guessCount = 0; var correctGuess = false;//flag
function getRandomNumber( upper ) { var num = Math.floor(Math.random() * upper) + 1; return num; } do{ guess=propmt("I am thinking of a number between 1 and 6 ,what is it?"); guessCount +=1; if(parseInt(guess)===randomNumber){ correctGuess = true; // flag}
} while(!correctGuess);// as long player hasnt got correct random keep reapeating document.write("it took you " + guessCount + "tries to guess the correct number" + randomNumber);
VM58:23 Uncaught SyntaxError: Unexpected end of input var randomNumber = getRandomNumber(10); var guess; var guessCount = 0; var correctGuess = false;//flag
function getRandomNumber( upper ) { var num = Math.floor(Math.random() * upper) + 1; return num; } do{ guess=propmt("I am thinking of a number between 1 and 6 ,what is it?"); guessCount +=1; if(parseInt(guess)===randomNumber){ correctGuess = true; // flag}
}} while(!correctGuess)// as long player hasnt got correct random keep reapeating document .write("it took you " + guessCount + "tries to guess the correct number" + randomNumber);</p>
3 Answers
KRIS NIKOLAISEN
54,971 PointsI see four issues
1) The syntax error is from missing a closing bracket. It looks like you have one that has been commented out
correctGuess = true; // flag}
2) You have misspelled prompt
as propmt
3) You prompt the user for a random number between 1 and 6 but generate a number between 1 and 10
4) Spaces should be added to the message you write so the numbers are separated from text
Here is an update:
var randomNumber = getRandomNumber(6);
var guess;
var guessCount = 0;
var correctGuess = false;//flag
function getRandomNumber( upper ) {
var num = Math.floor(Math.random() * upper) + 1;
return num;
}
do{
guess=prompt("I am thinking of a number between 1 and 6 ,what is it?");
guessCount +=1;
if(parseInt(guess)===randomNumber){
correctGuess = true; // flag
}
} while(!correctGuess);// as long player hasnt got correct random keep reapeating
document.write("It took you " + guessCount + " tries to guess the correct number " + randomNumber);
Jamie Reardon
Treehouse Project ReviewerYou need to add your code in order for people to assist you. Please refer to using the markdown syntax to embed your code. Alternatively, add it to a workspace that we can see.
Tlaleng Ramoroke
1,627 Pointsvery helpful thank you .