Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Basics Making Decisions in Your Code with Conditional Statements The Conditional Challenge

DWAYNE RAINFORD
DWAYNE RAINFORD
1,204 Points

The Conditional Challenge

I'm getting an error on 'line 55' of my code, unsure why as the conditional seems to be correct. Can anyone help?

/*

  1. Store correct answers
    • When quiz begins, no answers are correct */

let correctGuess = 0;

// 2. Store the rank of a player

let playerRank = "No crown";

// 3. Select the <main> HTML element

document.querySelector = 'main'; /*

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

const Q1 = prompt("What is your favorite car?"); if( Q1 === "Lancia Delta Integrale." ) { correctGuess +=1; } const Q2 = prompt("What's you dream motorcycle?"); if ( Q2 === "BMW S1000rr M.") { correctGuess +=1; } const Q3 = prompt("What do you miss about riding?"); if(Q3 === "The freedom." ) { correctGuess +=1; } const Q4 = prompt("What car do you have currently?"); if( Q4 === "VW Golf Mk4 Anniversary") { correctGuess +=1; } const Q5 = prompt("What's your favorite feature on your car?"); if(Q5 === "The aftermarket alloy wheels.") { correctGuess +=1; } /*

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

"conditionals" */

if(correctGuess === 5) { playerRank = "Gold"; } else if { <<<<<<<-----------------This is the line where the console logs an error (correctGuess => 3 && =< 4) playerRank = "Silver"; } else if { (correctGuess =< 2 || => 1 ) playerRank = "Bronze"; } else { (correctGuess =< 2) playerRank = "No crown"; }

// 6. Output results to the <main> element

document.querySelector('main').innerHTML = <h2>You got: ${correctGuess} out of 5 questions correct.Your rank is ${playerRank}</h2>;

Good Afternoon,
I am looking specifically at your conditionals: One of your issues is that you are using && instead of ||. You are also using a short hand for function which is => instead of <= or >= the location of the <> matters. For this case you don't need to specify if the score is greater than or less than because it needs to be (===) strictlyEqual to the specified number to meet the requirements for the rank. for example:

if (correctGuess === 3 || correctGuess === 4) { playerRank = "Silver"; } I am working this code as we speak so I have a few things to work out. Hang in there!

1 Answer

DWAYNE RAINFORD
DWAYNE RAINFORD
1,204 Points

correctGuess =< 2) playerRank = "No crown"; } - Just seen that this is incorrect and have changed to:

correctGuess = 0) playerRank = "No crown"; }