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 trialZaal Rottunda
Full Stack JavaScript Techdegree Student 1,796 PointsMy code isn't generating the prompts after prompt 1, not sure why?
*
- 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("Why am I doing this to myself?"); if ( answer1 = "I dont quite remember"){ correct+= 1; } const answer2= prompt("What am I missing?"); if (answer2= "Maybe just more pracice"){ correct+= 1; } const answer3 = prompt("Do you think you need to spend more time daily?"); if (answer3= "Yes."){ correct+= 1; } const answer4 = prompt("Do you think you can commit to an hour a day?"); if (answer4= "Yes I'll try"){ correct+=1; } const answer5 = prompt("Do you think you still workout as often?"); if (answer5= "Yes I'll try"){ 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 = "None :(";
}
// 6. Output results to the <main> element
main.innerHTML=
<h2>You got ${correct} out of 5 quesions correct.</h2>
<p> Crown earned: <strong>${rank}</strong></p>
;
2 Answers
Steven Parker
231,265 PointsWhen you wrote if ( answer1 = "I dont quite remember")
, you probably meant to use the equality operator (==
) instead. A single equal sign is an assignment operator, and reassigning a constant is not allowed and causes the program to stop.
For future questions, a much better way to share your code is with a workspace snapshot (note: not "screenshot").
You might want to take a look at this video about sharing a snapshot of your workspace.