JSFiddle - React, Tailwind, and code Playground
JavaScript
/* Quiz: Ask 5 questions, keep track of the number of questions answered correctly, provide results with how many questions they got right and give player a ranking */
/*5 Star Wars questions, stored in separate variables */
var questionOne = prompt("What is the name of Han Solo\'s furry friend?");
var questionTwo = prompt("What is the last name of Luke?");
var questionThree = prompt("What is the name of the dark side\'s secret weapon?");
var questionFour = prompt("What is the name of Luke\'s father?");
var questionFive = prompt("What is the first name of the mysterious man Han solo and everyone else visits?");
//Contain correct answers and count each correct answer as a point/
if (questionOne === 'Chewbacca') {
var answerOne = 1;
}
if (questionTwo === 'Skywalker') {
var answerTwo = 1;
}
if (questionThree === 'Death Star') {
var answerThree = 1;
}
if (questionFour === 'Darth Vader') {
var answerFour = 1;
}
if (questionFive === 'Lando') {
var answerFive = 1;
}
//Compare points earned and give a score/
if (answerOne + answerTwo + answerThree + answerFour + answerFive == 5) {
console.log('Congrats, you have earned the Gold Star!')
}
if (answerOne + answerTwo + answerThree + answerFour + answerFive == 2 || answerOne + answerTwo + answerThree + answerFour + answerFive == 3 || answerOne + answerTwo + answerThree + answerFour + answerFive == 4) {
console.log('Congrats, you have earned the Silver Star!')
}
if (answerOne + answerTwo + answerThree + answerFour + answerFive == 1) {
console.log('You have earned the Bronze Star!')
}