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 trialJesus Abarca
1,814 PointsCant seem to get my correct answers to add up
/*
- Store correct answers
- When quiz begins, no answers are correct */ let correct =0;
// 2. Store the rank of a player let rank=``
// 3. Select the <main> HTML element
const main = document.querySelector(main
);
/*
- Ask at least 5 questions
- Store each answer in a variable
- Keep track of the number of correct answers */ const answer1= prompt("who is the best right back of all time?"); if (answer1.toUpperCase() === 'Alves') { correct += 1; }
const answer2= prompt("Who is the the all time champions league top scorer?"); if (answer2.toUpperCase()==='Ronaldo') { correct += 1; }
const answer3= prompt("What mexican player is a treble winner?") if (answer3.toUpperCase()==='Marquez') { correct += 1; }
const answer4= prompt("What team has 13 champions leagues?") if (answer4.toUpperCase()==='Real Madrid') { correct += 1; }
const answer5= prompt("which league is claimed to be the best and hardest to win?") if (answer5.toUpperCase()==='Premier League') { correct += 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 ( correct === 5 ) {
rank = "Gold";
} else if ( correct >= 3 ) {
rank = "Silver";
} else if ( correct >= 1 ) { // check for 1-2 correct rank = "Bronze";
} else { rank = "None :("; }
// 6. Output results to the <main> element
main.innerHTML=
<h2> You got ${correct} out of 5 questions correct.</h2>
<p>Crown earned:<strong>${rank}</strong></p>
;
1 Answer
Simon Coates
8,377 PointsIs it that you're converting the received answers to uppercase, but comparing them against normal case answer? So for instance, you might need:
if (answer2.toUpperCase()==='RONALDO') {
rather than
if (answer2.toUpperCase()==='Ronaldo') {
Jesus Abarca
1,814 PointsJesus Abarca
1,814 PointsThanks so much Simon that was the problem indeed!