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 JavaScript Basics (Retired) Making Decisions with Conditional Statements The Conditional Challenge Solution

Michael Elmallakh
Michael Elmallakh
2,531 Points

My program doesn't work

//quiz begin, no answer correct
var correct = 0;

 //Start the questions 

 var answer1 = prompt("What is your first name???");
 if (answer1.toUpperCase() === "Michael") {
    correct += 1;
 }
var answer2 = prompt("What is your father name???");
if (answer2.toUpperCase() === "Amir") {
    correct += 1;
}
var answer3 = prompt('where do you live???' );
if (answer3.toUpperCase() === "Egypt") {
    correct += 1;
}
var answer4 = prompt("What you are learning now??");
if (answer4.toUpperCase() === "Coding") {
    correct += 1;
}
var answer5 = prompt("What is your favorite team");
if (answer5.toUpperCase() === "Germany") {
    correct += 1;
}


//output result 
document.write('<p> You have answered ' + correct + ' question correctly. </p>'); 

//output rank
if ( correct === 5) {
    document.write("<p> You got the gold medal </p>");
}else if( correct >= 3 ) {
    document.write("<p> You got the silver</p>");
}else if( correct >= 1 ) {
    document.write("<p> You got the bronze</p>");
}else{
    document.write("<p> You got nothing</p>")
}

3 Answers

Hey Michael your code is correct with the exception of your conditional statements.

 var answer1 = prompt("What is your first name???");
 if (answer1.toUpperCase() === "MICHAEL") {
    correct += 1;
 }
var answer2 = prompt("What is your father name???");
if (answer2.toUpperCase() === "AMIR") {
    correct += 1;
}
var answer3 = prompt('where do you live???' );
if (answer3.toUpperCase() === "EGYPT") {
    correct += 1;
}
var answer4 = prompt("What you are learning now??");
if (answer4.toUpperCase() === "CODING") {
    correct += 1;
}
var answer5 = prompt("What is your favorite team");
if (answer5.toUpperCase() === "GERMANY") {
    correct += 1;
}

I hope this helps.

What did you change Chyno Deluxe?

Hey Kenneth, I had changed all answer strings to uppercase. (i.e "Germany" to "GERMANY").

Micheal had changed the users initial answers to uppercase using the .toUpperCase() method but the answers he was comparing too were NOT all uppercase. So his code would never add any correct answers.

I hope this helps.

Yes, thank you so much! It really made sense once I figured out that toUppercase means that the result will be all CAPS. So if it's all CAPS then the result has to be all CAPS. Thanks so much!