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

DWAYNE RAINFORD
DWAYNE RAINFORD
1,379 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,379 Points

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

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