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 trialNelson Lourenco
1,766 PointsQuiz outputting incorrect
// quiz begins, no answers correct var correct = 0;
// Question 1 var answerOne = prompt('What color are frogs typically?'); if ( answerOne.toUpperCase() === 'GREEN') { correct += 1; }
// Question 2 var answerTwo = prompt('How many arms does an octopus have?'); if ( answerTwo.toUpperCase() === '8') { correct += 1; }
// Question 3 var answerThree = prompt('Which sauce can you make with avocados?'); if (answerThree.toUpperCase() === 'Guacomole') { correct += 1; }
// output rank if ( correct === 3 ) { document.write("I hereby give you a GOLD CROWN!"); } else if ( correct === 2 ) { document.write("I hereby give you a SILVER CROWN!"); } else if ( correct === 1 ) { document.write("I hereby give you a BRONZE CROWN!"); } else if ( correct === 0 ) { document.write("I hereby give you GOOSE EGGS!"); }
--
How come when I get all 3 answers correct, that I am still getting a silver crown?
1 Answer
Marcus Parsons
15,719 PointsHi Nelson,
The problem lies in your 3rd if statement. You are transferring answerThree to an uppercase format but not comparing it to an uppercase string. You need "GUACAMOLE" and not "Guacamole" for your string. Btw, I put guacamole as its correct spelling :P
// quiz begins, no answers correct
var correct = 0;
// Question 1
var answerOne = prompt('What color are frogs typically?');
if ( answerOne.toUpperCase() === 'GREEN') {
correct += 1;
}
// Question 2
var answerTwo = prompt('How many arms does an octopus have?');
if ( answerTwo.toUpperCase() === '8') {
correct += 1;
}
// Question 3
var answerThree = prompt('Which sauce can you make with avocados?');
//changed Guacomole to GUACAMOLE
if (answerThree.toUpperCase() === 'GUACAMOLE') {
correct += 1;
}
// output rank
if ( correct === 3 ) {
document.write("I hereby give you a GOLD CROWN!");
}
else if ( correct === 2 ) {
document.write("I hereby give you a SILVER CROWN!");
}
else if ( correct === 1 ) {
document.write("I hereby give you a BRONZE CROWN!");
}
else if ( correct === 0 ) {
document.write("I hereby give you GOOSE EGGS!");
}