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 Making Decisions in Your Code with Conditional Statements The Conditional Challenge Solution

Naoki Yoshida
Naoki Yoshida
6,984 Points

When I make a conditional between two variables, it never outputs a true. Why is that?

I know my method wasn't the most efficient. Already saw the solution video and I know it wasn't necessary to make a variable out of the correct answer but I did it.

It should work and it doesn't.

if (submit1.toUpperCase === answer1){ correctAnswers += 1; }

The result is always false. Why is that?? Thanks in advance.

This is my code:

/*

  1. Store correct answers
    • When quiz begins, no answers are correct */ const answer1 = "HTML"; const answer2 = "CSS"; const answer3 = "JAVASCRIPT"; const answer4 = "PRACTICE"; const answer5 = "PRACTICEX2";

// 2. Store the rank of a player

let rank; let correctAnswers = 0;

// 3. Select the <main> HTML element

const main = document.querySelector('main');

/*

  1. Ask at least 5 questions
    • Store each answer in a variable
    • Keep track of the number of correct answers */

let submit1 = prompt ("What's the first thing you gotta learn to become a web developer?"); if (submit1.toUpperCase === answer1){ correctAnswers += 1; } console.log(submit1); console.log(correctAnswers);

let submit2 = prompt ("What's the second thing you gotta learn to become a web developer?"); if (submit2.toUpperCase === answer2){ correctAnswers += 1; } console.log(submit2);

let submit3 = prompt ("What's the third thing you gotta learn to become a web developer?"); if (submit3.toUpperCase === answer3){ correctAnswers += 1; } console.log(submit3);

let submit4 = prompt ("What's the fourth thing you gotta learn to become a web developer?"); if (submit4.toUpperCase === answer4){ correctAnswers += 1; } console.log(submit4);

let submit5 = prompt ("What's the fifth thing you gotta learn to become a web developer?"); if (submit5.toUpperCase === answer5){ correctAnswers += 1; } console.log(submit5);

console.log(correctAnswers);

/*

  1. Rank player based on number of correct answers
    • 5 correct = Gold
    • 3-4 correct = Silver
    • 1-2 correct = Bronze
    • 0 correct = No crown */

if (correctAnswers == 0) { rank = "No"; } else if (correctAnswers == 1 || correctAnswers == 2) { rank = "Bronze"; } else if (correctAnswers == 3 || correctAnswers == 4) { rank = "Silver"; } else if (correctAnswers == 5) { rank = "Gold"; } // 6. Output results to the <main> element

main.innerHTML = <h1>According to the results: You earned ${rank} crown!</h1>

2 Answers

Have you tried adding parentheses to call the method? submit1.toUpperCase()

Naoki Yoshida
Naoki Yoshida
6,984 Points

Yes! It was that syntax error. Thanks!