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 trialsimsima
Courses Plus Student 2,560 PointsThis isn't adding up
/*
1. Store correct answers
- When quiz begins, no answers are correct
*/
let correctAnswer = 0
// 2. Store the rank of a player
let rank;
// 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 q1 = prompt(` Are multi-line comments started and ended with " /* */ " `);
if (q1.toUpperCase() === 'YES' || q1.toUpperCase() === 'Y'){
correctAnswer +=1;
console.log(correctAnswer);
}
const q2 = prompt(` Are single comments started and ended with " // " `);
if (q2.toUpperCase() === 'YES' || q1.toUpperCase() === 'Y'){
correctAnswer +=1;
console.log(correctAnswer);
}
const q3 = prompt(` Are you learning JavaScript ???" `);
if (q3.toUpperCase() === 'YES' || q1.toUpperCase() === 'Y'){
correctAnswer +=1;
console.log(correctAnswer);
}
const q4 = prompt(`Does this quiz suck ???`);
if (q4.toUpperCase() === 'YES' || q1.toUpperCase() === 'Y'){
correctAnswer +=1;
console.log(correctAnswer);
}
const q5 = prompt(` are we done yet ????`); \\jokes
if (q5.toUpperCase() === 'YES' || q1.toUpperCase() === 'Y'){
correctAnswer +=1;
console.log(correctAnswer);
}
/*
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 ( correctAnswer === 5){
rank =`👑👑👑👑👑 Gold`;
} else if( correctAnswer >= 3 ) {
rank =`👑👑👑 Silver`;
} else if( correctAnswer >= 2 ){
rank =`👑👑 Bronze`;
} else
rank = `No Crown`;
// 6. Output results to the <main> element
let results = `<p> The results is you got ${rank}</p>`;
main.innerHTML = results;
1 Answer
Bella Bradbury
Front End Web Development Techdegree Graduate 32,790 PointsHi there Simsima! I've taken a look at your code and there's just a few syntax errors that are preventing your code from running. The first thing you're going to want to do is to look at line 6 where you're defining correctAnswer. You'll want to make sure to put the ;
at the end of the line.
The next thing to look at is line 54 where you've written an in-line comment. You have the right idea, but the wrong slash! You'll want to change those from back-slashes \\ to forward-slashes //
.
The last syntax error you'll need to change is at lines 76 and 78. Even though it's the last conditional, it still needs curly brackets. Writing your code as follows will fix that error:
} else {
rank = `No Crown`;
}
The above changes will remove the errors that are blocking your app from running! There is one more error, but it's in how the program is ranking the players. I'll leave this one to you to figure out! Just look back over the directions and how many correct answers it takes to get the different rankings ;)
Hope this helps!
simsima
Courses Plus Student 2,560 Pointssimsima
Courses Plus Student 2,560 PointsWhen debugging via the console log it is incrementing once the first response is given with 'yes' response. Even it if do not input anything it seems the logic is to increment.
i don't understand what is going on ?
I placed the console outside the conditional as well.
thank you for your time