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 trialGlenn Ramsay
4,257 PointsPrompts are not showing
I'm not sure where my error is I see the error in line 54 which shows in the console but I don't have the prompts showing and they run before that code
/*
1. Store correct answers
- When quiz begins, no answers are correct
*/
let score = 0
// 2. Store the rank of a player
let rank = "no crown"
// 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 planet = prompt("what planet are we on");
if (planet === "earth"){
score +=1;
}
const color = prompt("what is the color of a Banana");
if (color === "yellow"){
score +=1;
}
const fruit = prompt("what is a yellow fruit");
if (fruit === "banana"){
score +=1;
}
const car = prompt("what is the color of a hearst");
if (car === "black"){
score +=1;
}
const juice = prompt("what is the best juice");
if (planet === "orange"){
score +=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 (score === 5){
rank = "Gold"
} else if (score>=3 && score <5){
rank = "Silver"
}else if (score>=1 && score <3){
rank = "Bronze"
}
// 6. Output results to the <main> element
main.innerHTML= `<h2>`You scored ${} out 5 questions</h2>
<p>Your rank is ${rank}</p>`};
edited to add markdown
2 Answers
Jennifer Nordell
Treehouse TeacherHi there, Glenn Ramsay ! Some errors are severe enough to cause the script to halt execution, even if the errors are further down in the script. Such is the case here.
At the bottom you have:
main.innerHTML= `<h2>`You scored ${} out 5 questions</h2>
<p>Your rank is ${rank}</p>`};
But as you can probably tell from the odd coloring, you've ended the template literal a bit prematurely. There's a backtick right after <h2>
that shouldn't be there. There's also a stray closing curly brace at the end.
Try:
main.innerHTML= `<h2>You scored ${} out 5 questions</h2> // removed the stray backtick on this line
<p>Your rank is ${rank}</p>`; // removed the stray curly brace on this line
Hope this helps!
Laura Owens
15,044 PointsI think your code looks fine, you're just missing a few basic things. I'm using Visual Studio Code (free) to write my code instead of Workspaces. It highlights and color codes things to help you spot errors. I also use the Debug Console that displays an error log. One of the answers to a different question in this lesson suggested the person check their error log. You can probably read that answer to find out how to use it on Workspaces.
You need semicolons after your "let" statements in #1 and #2.
In #5, check the end of the "if" statement for something missing there too.
In #6, you have:
// 6. Output results to the <main> element
main.innerHTML= <h2>
You scored ${} out 5 questions</h2>
<p>Your rank is ${rank}</p>`};
Check your use of the the backtick for the template literals. If you click on the first one before <h2>, find the matching "closing" backtick. Fix that and most of that line of code will work. Next look at the ${} ... did you mean to put a variable in there?
Don't let the "stoopid" little things get you down. This is how you learn. I've been an editor for 20+ years so these just jump out at me. When I first learned to code 40 yrs ago, I'd get frustrated after putting so much work into a program then not seeing why it wasn't working. When you feel that way, it's time for a walk around the block ... or a milkshake ... or 5 minutes of DOOM. After a break you'll have fresh eyes. I hear yoga works ... but ... beating my head against the wall is more familiar.
Mary Kong
1,146 PointsThanks Laura so much for the advice!
Mary Kong
1,146 PointsMary Kong
1,146 PointsGlenn, I definitely ran into some of the same issues with some parts working and others not. It was helpful to be reminded to test code as you are writing it. For some reason, I could not get the final text to appear via the preview, but I was able to test and have it work on the developer console. I have since got it to work. Good luck, this was definitely a difficult challenge.