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 trialShung Chen
6,526 Pointsjavascript value does not hold / store / add-up
It looks like the following code does not add to the total correct value with answers are correct or not...
/*
- 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 Q1 = prompt('What is the answer fo Question_1'); if ( Q1.toUpperCase === 'MON' ){ correct += 1; } const Q2 = prompt('What is the answer fo Question_2'); if ( Q1.toUpperCase === 'TUE' ){ correct += 1; }
const Q3 = prompt('What is the answer fo Question_3'); if ( Q1.toUpperCase === 'WED' ){ correct += 1; }
const Q4 = prompt('What is the answer fo Question_4'); if ( Q1.toUpperCase === 'THUR' ){ correct += 1; }
const Q5 = prompt('What is the answer fo Question_5'); if ( Q1.toUpperCase === 'FRI' ){ 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 ) { rank = "Bronze"; } else { rank = "Nothing"; }
// 6. Output results to the <main> element
main.innerHTML = You got ${correct} out of 5 questions correct.
Great you are ${rank}
;
1 Answer
Steven Parker
231,153 PointsWhen posting code to the forum, use Markdown formatting to preserve the appearance, or share the entire workspace by making a snapshot and posting the link to it.
But even unformatted, two things stood out at first glance:
- when calling a method, the name must always be followed by parentheses
Q1.toUpperCase()
- all of the questions are testing Q1 (instead of Q1-Q5)