 # Score Calculation for Quiz Not Working

Hello,

I’m working on writing a javascript console program for a quiz that takes user input. I’m using arrays for questions and answers and loops to iterate through the questions. I’m having issues with the score calculations not working correctly. i’m trying to figure out a way to construct an array of user answers and compare it to the correct answer key.

i’m also wanting to figure out how to make the input case insensitive so ‘sally ride’ and ‘Sally Ride’ will both be accepted.

here is what i have with notes.

let candidateName = input.question(“What is your name?”);
console.log(“Candidate Name:”, candidateName);

//build question bank
let question1 = (`1) True or false: 5000 meters = 5 kilometers.`);
let question2 = (`2) (5 + 3)/2 * 10 = ?`);
let question3 = (`3) Given the array [8, "Orbit", "Trajectory", 45], what entry is at index 2?`);
let question4 = (`4) Who was the first American woman in space?`);
let question5 = (`5) What is the minimum crew size for the International Space Station (ISS)?`)
let questionBank = [question1, question2, question3, question4, question5];

let ans1 = true;
let ans2 = 40;
let ans3 = “trajectory”;
let ans4 = “Sally Ride”;
let ans5 = 3;
let answerKey = [ans1, ans2, ans3, ans4, ans5];

//run quiz

let candidateResponse=;
let correctResponses = 0
let i = 0;

while(i < questionBank.length) {

//outer loop

``````console.log("Correct Answer:",answerKey[i], "\n");
//inner loop
candidateResponse = candidateResponse + input.question;
//for()
``````

i++;
correctResponses = correctResponses +1;}
}

for (i = 0; i < 5; i++) {
if (typeof candidateResponse !== Number) {
candidateResponse[i].toLowerCase();
} else {
console.log(candidateResponse[i]);
}
}

let scoreCounter = 0;
console.log(`>>> Overall Grade: \${percentage}% (\${scoreCounter} of 5 responses correct) <<<`);

if (percentage > 70) {
console.log(">>>Status: PASSED <<<")
} else {
console.log(">>> Status: FAILED <<<")

}
correctResponses = correctResponses +1;
} i++
}

hi @DDufner
So you want to create a quiz app and after I have seen how you storing the question and answers separately, I suggest you create an array of objects and each object has two properties one for the question and other for the answer

``````const quizzes = [
{
question : "True or false: 5000 meters = 5 kilometers.",
},
{
question : "(5 + 3)/2 * 10 = ?.",
}
];
``````

and know you can loop this array , and ask the user, get thier answer back and test if thier answer is correct to calculate the score , exemple :

``````let score = 0;
for (let quiz in quizzes) {