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

Can't get my code to work with the quiz. Not sure what I am doing wrong. Everything looks correct, score not working.

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

let correctAnswers = 0;


// 2. Store the rank of a player

let playerRank = '';


// 3. Select the <main> HTML element
const main = document.querySelector('main')

/*
  4. Ask at least 5 questions
   - Store each answer in a variable
   - Keep track of the number of correct answers
*/
const answerOne = prompt("Who was the first name of our first president?");
if (answerOne.toUpperCase() === "George") {
  correctAnswers += 1;
}

const answerTwo = prompt("What is the third month of the year?");
if (answerTwo.toUpperCase() === "March") {
  correctAnswers += 1;
}

const answerThree = prompt("What fruit a day keeps the doctor away?");
if (answerThree.toUpperCase() === "Apple") {
  correctAnswers += 1;
}

const answerFour = prompt("Who created Apple?");
if (answerFour.toUpperCase() === "Steve Jobs") {
  correctAnswers += 1;
}

const answerFive = prompt("What animal is Pepe Le Pew?");
if (answerFive.toUpperCase() === "Skunk") {
 correctAnswers += 1;
}

/*
  5. 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 === 5) { 
  playerRank = "Gold";
} else if (correctAnswers >= 3) { 
  playerRank = "Silver"; 
} else if (correctAnswers >= 1) { 
  playerRank = "Bronze"; 
} else { 
  playerRank = "None :("
}


// 6. Output results to the <main> element
main.innerHTML = `
<h2>Thank you for playing, you got ${correctAnswers} correct questions!</h2>
<p>Crown earned: <strong>${playerRank}</strong></p>
/* 
  1. Store correct answers
   - When quiz begins, no answers are correct
*/

let correctAnswers = 0;


// 2. Store the rank of a player

let playerRank = '';


// 3. Select the <main> HTML element
const main = document.querySelector('main')

/*
  4. Ask at least 5 questions
   - Store each answer in a variable
   - Keep track of the number of correct answers
*/
const answerOne = prompt("Who was the first name of our first president?");
if (answerOne.toUpperCase() === "George") {
  correctAnswers += 1;
}

const answerTwo = prompt("What is the third month of the year?");
if (answerTwo.toUpperCase() === "March") {
  correctAnswers += 1;
}

const answerThree = prompt("What fruit a day keeps the doctor away?");
if (answerThree.toUpperCase() === "Apple") {
  correctAnswers += 1;
}

const answerFour = prompt("Who created Apple?");
if (answerFour.toUpperCase() === "Steve Jobs") {
  correctAnswers += 1;
}

const answerFive = prompt("What animal is Pepe Le Pew?");
if (answerFive.toUpperCase() === "Skunk") {
 correctAnswers += 1;
}

/*
  5. 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 === 5) { 
  playerRank = "Gold";
} else if (correctAnswers >= 3) { 
  playerRank = "Silver"; 
} else if (correctAnswers >= 1) { 
  playerRank = "Bronze"; 
} else { 
  playerRank = "None :("
}


// 6. Output results to the <main> element
main.innerHTML = `
<h2>Thank you for playing, you got ${correctAnswers} correct questions!</h2>
<p>Crown earned: <strong>${playerRank}</strong></p>

1 Answer

Robert Manolis
STAFF
Robert Manolis
Treehouse Guest Teacher

Hey Jared Barnes , it looks like the issue might be that you're using the .toUpperCase() method on the user's response, but then comparing that to a string that is only capitalized, but not uppercased. Try changing the correct answers in the if statement conditions to all uppercase letters. I think that will help. :thumbsup:

Thank you, Robert Manolis! It works now.