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 trialJames Summers
704 PointsMY CODE
Here's my code. Mr. Guil said to share so here it is: /*
- Store correct answers
- When quiz begins, no answers are correct */ let score = 0;
// 2. Store the rank of a player let rank = "None";
// 3. Select the <main> HTML element document.querySelector('main');
/*
- Ask at least 5 questions
- Store each answer in a variable
- Keep track of the number of correct answers */ const QUIZ = prompt("What coding languge is also the name of a snake?");
if ( QUIZ.toUpperCase() === "PYTHON") { score += 1 alert("You are right!"); } else{ alert("WRONGNESS! It was Python!"); }
const quiz = prompt("What planet is closest to the sun?");
if ( quiz.toUpperCase() === "MERCURY") { score += 1 alert("RIGHT!"); } else{ alert("Incorrect!"); }
const QuIz = prompt("What is the biggest city in the world?")
if ( QuIz.toUpperCase() === "CHONGQING") { score += 1 alert("CORRECT!"); } else{ alert("WRONGQING! IT was Chongqing!"); }
const quiZ = prompt("What replaces the I in PIXAR at the beginning of PIXAR movies?");
if ( quiZ.toUpperCase() === "A LAMP") { score += 1 alert("You are right!"); } else { alert("YOU'RE WRONG!!! IT was a lamp!"); }
const Quiz = prompt("Is Pluto a planet, an icy drawf planet, an asteroid, or an ouyotraed?");
if ( Quiz.toUpperCase() === "AN ICY DRAWF PLANET") { score += 1 alert("You were right! It's not a planet or an asteroid, and an ouyotraed doesn't exist!"); } else { alert("YOU WAS WRONG!!! IT WAS AN ICY DRAWF PLANET!"); }
/* 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 === 4 || score === 3) {
rank = "Silver"
} else if ( score === 1 || score === 2) {
rank = "bronze"
} else {
rank = "No"
}
// 6. Output results to the <main> element
main.innerHTML =
<h2>You got ${score} out of 5 questions correct!</h2> <p>Crown Earned: <strong>${rank}</strong> <p>
;
1 Answer
Steven Parker
231,268 PointsWhen posting code, use Markdown formatting to preserve the code's appearance and retain special symbols. Another way to share code and make it easy to replicate is to make a snapshot of your workspace and post the link to it here.
The blue links lead to tutorial videos for each concept.
James Summers
704 PointsJames Summers
704 PointsThank you, Mr. Parker.