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 trialchristian bugay
4,260 PointsMy code doesn't run past the first prompt!
Why doesn't it run past the first prompt? Here's my code:
var numCorrectAnswers = 0;
var ansOne = prompt( "What is 1 + 1"); if ( parseInt(asnOne) === 2 ) { numCorrectAnswers += 1; } var ansTwo = prompt( "What is 2 + 1"); if ( parseInt(ansTwo) === 3 ) { numCorrectAnswers += 1; } var ansTres = prompt( "What is 3 + 1"); if ( parseInt(asnTres) === 4 ) { numCorrectAnswers += 1; } var ansFour = prompt( "What is 2 + 2"); if ( parseInt(asnFour) === 4 ) { numCorrectAnswers += 1; } var ansFive = prompt( "What is 1 + 0"); if ( parseInt(asnFive) === 1 ) { numCorrectAnswers += 1; }
if ( numCorrectAnswers === 5 ) {
alert("You won the GOLD CROWN!");
} else if ( numCorrectAnswers === 4 ) {
alert("You won the SILVER CROWN!");
} else if ( numCorrectAnswers === 3 ) {
alert("You won the BRONZE CROWN!");
} else if ( numCorrectAnswers === 2 ) {
alert("You won the CHROME CROWN!");
} else if ( numCorrectAnswers === 1 ) {
alert("You won the WOODEN CROWN!");
} else {
alert("Go Home, You're Drunk!");
}
1 Answer
Codey Novice
Full Stack JavaScript Techdegree Student 2,022 PointsThe variable is misspelled in your first conditional statement after your first prompt.
if ( parseInt(asnOne) === 2 ).
The code contains 2 transposed letters: the n and s of ansOne
Codey Novice
Full Stack JavaScript Techdegree Student 2,022 PointsCodey Novice
Full Stack JavaScript Techdegree Student 2,022 PointsFYI: I did NOT check the remainder of the code past that first mistake.
christian bugay
4,260 Pointschristian bugay
4,260 PointsThanks! I guess I was a little sleepy when I wrote it.