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 trialSam Weeks
Front End Web Development Techdegree Student 16,699 PointsJust not working
Followed Guil's code exactly in the end and I still couldn't get this to work; Can anyone help Thank you
1. 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');
/*
4. Ask at least 5 questions
- Store each answer in a variable
- Keep track of the number of correct answers
*/
const questOne = prompt("Name a programming language that's also a gem.");
if (questOne.toUpperCase() === "RUBY") {
correct += 1;
}
const questTwo = prompt("Name a programming language that's also a snake");
if (questTwo.toUpperCase() === "PYTHON") {
correct += 1;
}
const questThree = prompt('What programming language do you use to style web pages?');
if (questThree.toUpperCase === "CSS") {
correct += 1;
}
const questFour = prompt('What language do you use to build the structure of a web page?');
if (questFour.toUpperCase === "HTML") {
correct += 1;
}
const questFive = prompt('What language do you use to add interactivity to a web page?');
if (questFive.toUpperCase === "JAVASCRIPT") {
correct += 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 (correct === 5) {
rank = "Gold Crown";
} else if (correct >= 3 ) {
rank = "Silver Crown";
} else if (correct >= 2){
rank = "Bronze Crown";
} else {
rank = "None :(";
}
// 6. Output results to the <main> element
main.innerHTML = `<h2>You got ${correct} out of 5 questions</h2>
<p>Crowns Earned: <strong>${rank}</strong>`;
3 Answers
KRIS NIKOLAISEN
54,971 PointstoUpperCase
should be followed by parentheses in questions 3 - 5 like you did for questions 1 - 2.
Rinko Shopper
2,587 PointsI copied your code and it didn't work for me either, because a comment misses the beginning wrap here.
1. Store correct answers
- When quiz begins, no answers are correct
*/
For the future, try looking in the console, it tells you the exact line the error is made, if you think the logic of your code works, it's probably a syntax error (everyone misses something silly from time to time)
Sam Weeks
Front End Web Development Techdegree Student 16,699 PointsCheers guys thanks for this :) much appreciated!!!