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 trial![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![ChienTsun Chan](https://uploads.teamtreehouse.com/production/profile-photos/11704277/micro_MMC__518.jpg)
ChienTsun Chan
7,042 PointsShare my solution
/*
1. Store correct answers
- When quiz begins, no answers are correct
*/
const correctAnswer1 = "pizza";
const correctAnswer2 = 2015;
const correctAnswer3 = "POS";
const correctAnswer4 = "yes";
const correctAnswer5 = "no";
let correctAnswerCount = 0;
// 2. Store the rank of a player
let rankOfPlayer = "";
// 3. Select the <main> HTML element
/*
4. Ask at least 5 questions
- Store each answer in a variable
- Keep track of the number of correct answers
*/
// What is the first real thing traded by Bitcoin?
const answer1 = prompt("What is the first real thing traded by Bitcoin?");
if (answer1.toLowerCase() === correctAnswer1) {
correctAnswerCount += 1;
}
// Which year did Ethereum launch?
const answer2 = prompt("Which year did Ethereum launch?");
if (+answer2 === correctAnswer2) {
correctAnswerCount += 1;
}
// Which consensus mechanism is implemented on Ethereum?
const answer3 = prompt("Which consensus mechanism is implemented on Ethereum?");
if (answer3.toUpperCase() === correctAnswer3) {
correctAnswerCount += 1;
}
// Do current transactions in Ethereum follow EIP-1559 rule? (Yes or No)
const answer4 = prompt(
"Do current transactions in Ethereum follow EIP-1559 rule? (Yes or No)"
);
if (answer4.toLowerCase() === correctAnswer4) {
correctAnswerCount += 1;
}
// Dose Compound is a DEX?
const answer5 = prompt("Dose Compound is a DEX? (Yes or No)");
if (answer5.toLowerCase() === correctAnswer5) {
correctAnswerCount += 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 (correctAnswerCount === 5) {
rankOfPlayer = "Gold";
} else if (correctAnswerCount === 4 || correctAnswerCount === 3) {
rankOfPlayer = "Silver";
} else if (correctAnswerCount === 2 || correctAnswerCount === 1) {
rankOfPlayer = "Bronze";
} else {
rankOfPlayer = "no crown";
}
// 6. Output results to the <main> element
if (rankOfPlayer === "no crown") {
document.querySelector(
"main"
).innerHTML = `<h2>${correctAnswerCount} of 5 answers are correct.</h2>
<p>You get <strong>${rankOfPlayer}</strong> ! 😭</p>`;
} else {
document.querySelector(
"main"
).innerHTML = `<h2>${correctAnswerCount} of 5 answers are correct.</h2>
<p>You are ranked <strong>${rankOfPlayer}</strong> ! 🎉</p>`;
}