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

Randy Singh
seal-mask
.a{fill-rule:evenodd;}techdegree
Randy Singh
Full Stack JavaScript Techdegree Student 1,462 Points

Review of Quiz

Looking for a critique on my quiz. Specifically confused about the toLowerCase() and toUpperCase() and if I use a == instead of === for my answers.

//quiz begins, no answers correct var score = 0;

//alert box telling user quiz will begin alert('Welcome to the Conditional Quiz Challenge. Click OK to begin.');

/* Start the quiz Quesetions 1-5 */ var answer1 = prompt('what language am i studying right now?'); if (answer1.toLowerCase() === "javascript") { score +=1; } else { alert('Thats wrong. On to the next question. Click OK to continue'); }

var answer2 = prompt('where do I work?');
    if (answer2.toUpperCase() === "VITALS") {
        score +=1;
    }
    else {
    alert('Thats wrong. On to the next question. Click OK to continue');
}

var answer3 = prompt('Where was I born?');
    if (answer3.toLowerCase() == "paterson") {
    score +=1;
}
else {
    alert('Thats wrong. On to the next question. Click OK to continue');
}

var answer4 = prompt('what type of phone do I have?');
    if (answer4.toLowerCase() === "samsung galaxy s4 mini") {
        score +=1;
    }
    else {
    alert('Thats wrong. On to the next question. Click OK to continue');
}

// Let the user know they are approaching the last question alert('Last Question. Click OK to begin');

var answer5 = prompt('Who is the Greatest Of All Time?');
    if (answer5.toUpperCase() === "MUHAMMAD ALI") {
        score +=1;
    }
    else {
        alert('Thats wrong. Lets find out your score. Click OK to continue');
    }

// Let the user know how many questions they answered correctly document.write('you answered ' + score + ' out of a possible 5 questions');

//score counter if ( score === 5) { document.write('<p></p><p>You earned a gold medal.</p>'); } else if ( score >=3 ) { document.write('<p></p><p>You earned a silver medal.</p>'); } else if ( score >=1 ) { document.write('<p></p><p>You earned a bronze medal.</p>'); } else { document.write('<p></p><p>You got no questions correct and therefore have not earned a medal. Refresh the page to try again.</p>'); }

3 Answers

Randy,

Your code looks solid. The == is simply "equals to." Let's pretend x = 10: x == 8 (false) x == 10 (true) x == "10" (true)

=== requires equal value AND equal type. If x = 10 again: x === 7 (false) x === 10 (true) x === "10" (false). This is where the difference is. In this case x is an integer (10), and it's being compared to a string with "10" in it. If that makes sense?

As for the toUpperCase or toLowerCase, it doesn't matter which one you use. I'd suggest being consistent. The idea is to convert the users into something that isn't case sensitive. So if someone types in "Paterson", "paterson", or "paTerson"--it doesn't actually batter because your code will convert it to something that can be compared to the right answer.

Nick van der Sangen
Nick van der Sangen
11,516 Points

Hi Randy,

Like Dave has mentioned in a previous video, "Professional JavaScript programmers tend to use the triple equals operator. And avoid the double equals.". In the examples he combines it with the method .toUpperCase() or .toLowerCase().

You do want to be a professional JavaScript programmer, am I right? ;)