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

Jared Barnes
Jared Barnes
2,680 Points

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>
Jared Barnes
Jared Barnes
2,680 Points
/* 
  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
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
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:

Jared Barnes
Jared Barnes
2,680 Points

Thank you, Robert Manolis! It works now.