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

My code on Quiz application assignment is not working. Can someone take a look at it and let me know what is the error?

//quiz bigins with no correct answers yet var correctGuess = 0;

//ask questions var answer1 = prompt('what is the tallest mountain in the world'); if (answer1.toUpperCase () === "EVEREST") { correctGuess+= 1; }

var answer2 = prompt ('what is the deepest lake in the world'); if (answer2.toUpperCase ()=== "Baikal") { correctGuess+= 1; }

var answer3 = prompt ('Which US state has the hottest temperature'); if (answer3.toUpperCase ()=== "California") { correctGuess+= 1; } var answer4 = prompt ('what is the height of everest mountain in meters?'); if (parseInt(answer4 ))===8848; { correctGuess+= 1; } var answer5 = prompt ('what is the depth of lake Baikal in meters'); if (parseInt (answer5))===1,642; { correctGuess+= 1; }

//output results

document.write ('You got ' + correctGuess + 'out of 5 questions correct. </p>')

//output rank if (correctGuess === 5) { document.write (<p><strong>Your earned a gold crown</strong></p>); } else if (correctGuess >= 3) { document.write (<p><strong>Your earned a silver crown</strong></p>); } else if (correctGuess >= 1) { document.write (<p><strong>Your earned a bronze crown</strong></p>); } else { document.write (<p><strong>Your earned no crown</strong></p>); }

this is code i am trying to run that is not working var correctGuess = 0;

var answer1 = prompt('what is the tallest mountain in the world'); if (answer1.toUpperCase () === "EVEREST") { correctGuess+= 1; } var answer2 = prompt ('what is the deepest lake in the world'); if (answer2.toUpperCase ()=== "Baikal") { correctGuess+= 1; }

var answer3 = prompt ('Which US state has the hottest temperature'); if (answer3.toUpperCase ()=== "California") { correctGuess+= 1; } var answer4 = prompt ('what is the height of everest mountain in meters?'); if (parseInt(answer4 )===8848) { correctGuess+= 1; } var answer5 = prompt ('what is the depth of lake Baikal in meters'); if (parseInt (answer5)===1,642) { correctGuess+= 1; } document.write ('You got ' + correctGuess + 'out of 5 questions correct. </p>')

if (correctGuess === 5) { document.write (<p><strong>Your earned a gold crown</strong></p>); } else if (correctGuess >= 3) { document.write (<p><strong>Your earned a silver crown</strong></p>); } else if (correctGuess >= 1) { document.write (<p><strong>Your earned a bronze crown</strong></p>); } else { document.write (<p><strong>Your earned no crown</strong></p>); }

2 Answers

Hi Nurbek,

All thats needed to fix this is to put your correct guess conditional statements (in document.write) in quotes. Also make sure you define correctGuess=0 to begin with.

As a side note, strong would be better handled in CSS but for this example it wouldnt matter much.

HI Nurbek,

If all you would like to do is get this running then see my updates and explanations below. You may have lost some formatting from copy/ paste but Id recommend cleaning up the spacing for readability, allows you to find issues much faster. Your issues were mostly on line 9. if you are on Chrome you can check this by pressing F12 and debug from there (TW is my comment - the site removes my * after and before the slashes or else you could copy this straight to your comp and run it):

//quiz bigins with no correct answers yet /TW - copied the variable to a new line since commenting out using // commented out of defining the correct guess variable/ var correctGuess = 0;

//ask questions var answer1 = prompt('what is the tallest mountain in the world'); if (answer1.toUpperCase () === "EVEREST") { correctGuess+= 1; }

var answer2 = prompt ('what is the deepest lake in the world'); if (answer2.toUpperCase ()=== "Baikal") { correctGuess+= 1; }

var answer3 = prompt ('Which US state has the hottest temperature'); if (answer3.toUpperCase ()=== "California") { correctGuess+= 1; } var answer4 = prompt ('what is the height of everest mountain in meters?'); if (parseInt(answer4 )===8848) /TW - The parenthesis was in the wrong place here/

{correctGuess+= 1; } var answer5 = prompt ('what is the depth of lake Baikal in meters'); if (parseInt (answer5)===1,642) /TW - The parenthesis was in the wrong place here/{ correctGuess+= 1; }

//output results

document.write ('You got ' + correctGuess + ' out of 5 questions correct. </p>')

//output rank if (correctGuess === 5) { document.write (<p><strong>Your earned a gold crown</strong></p>); } else if (correctGuess >= 3) { document.write (<p><strong>Your earned a silver crown</strong></p>); } else if (correctGuess >= 1) { document.write (<p><strong>Your earned a bronze crown</strong></p>); } else { document.write (<p><strong>Your earned no crown</strong></p>); }

Tim, thanks for catching those errors. I fixed it, but it still not running.

var answer1 = prompt('what is the tallest mountain in the world'); if (answer1.toUpperCase () === "EVEREST") { correctGuess+= 1; } var answer2 = prompt ('what is the deepest lake in the world'); if (answer2.toUpperCase ()=== "Baikal") { correctGuess+= 1; }

var answer3 = prompt ('Which US state has the hottest temperature'); if (answer3.toUpperCase ()=== "California") { correctGuess+= 1; } var answer4 = prompt ('what is the height of everest mountain in meters?'); if (parseInt(answer4 )===8848) { correctGuess+= 1; } var answer5 = prompt ('what is the depth of lake Baikal in meters'); if (parseInt (answer5)===1,642) { correctGuess+= 1; }

document.write ('You got ' + correctGuess + 'out of 5 questions correct. </p>')

if (correctGuess === 5) { document.write (<p><strong>Your earned a gold crown</strong></p>); } else if (correctGuess >= 3) { document.write (<p><strong>Your earned a silver crown</strong></p>); } else if (correctGuess >= 1) { document.write (<p><strong>Your earned a bronze crown</strong></p>); } else { document.write (<p><strong>Your earned no crown</strong></p>); }

my console is pointing to line 29 which is document.write (<p><strong>Your earned a gold crown</strong></p>);

what is wrong with this line?