Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 43 additions & 21 deletions candidate-testing.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,74 @@
const input = require('readline-sync');

// TODO 2: modify your quiz app to ask 5 questions //

// TODO 1.1a: Define candidateName //
let candidateName;
let candidateName = "";
// TODO 1.2a: Define question, correctAnswer, and candidateAnswer //
let question;
let correctAnswer;
let candidateAnswer;
let question = "Who was the first American woman in space? ";
let correctAnswer = "Sally Ride";
let candidateAnswer = "";


//TODO: Variables for Part 2
let questions;
let correctAnswers;
let candidateAnswers;

let questions = ["Who was the first American woman in space? ",
"True or false: 5 kilometer == 5000 meters? ",
"(5 + 3)/2 * 10 = ? ",
"Given the array [8, 'Orbit', 'Trajectory', 45], what entry is at index 2? ",
"What is the minimum crew size for the ISS? "];
let correctAnswers = ["Sally Ride", "true", "40","Trajectory", "3"];
let candidateAnswers = [];

function askForName() {
// TODO 1.1b: Ask for candidate's name //
// TODO 1.1b: Ask for candidate's name //
candidateName = input.question("Enter your name here: ");


}

function askQuestion() {
// TODO 1.2b: Ask candidate the question and assign the response as candidateAnswer //


for(i = 0; i < questions.length; i++) {
candidateAnswers[i] = input.question(questions[i]);
console.log(`You answered: ${candidateAnswers[i]}\nCorrect Answer:${correctAnswers[i]}\n`);
}
}

function gradeQuiz(candidateAnswers) {

// TODO 1.2c: Let the candidate know if they have answered the question correctly or incorrectly //



let grade; //TODO 3.2 use this variable to calculate the candidates score.

let numberofCorrectAnswers = 0;
let grade = 0;

for (i = 0; i < questions.length; i++)
{
if (candidateAnswers[i].toLowerCase() === correctAnswers[i].toLowerCase())
{
numberofCorrectAnswers += 1
}
}
//TODO 3.2 use this variable to calculate the candidates score.
{}
grade = (numberofCorrectAnswers / questions.length) * 100;
if (grade < 80)
console.log(`>>> Overall Grade: ${grade} (${numberofCorrectAnswers}
of ${questions.length} responses correct) <<<
>>> Status: FAILED <<<`)
else if (grade >= 80) {
console.log(`>>> Overall Grade: ${grade} (${numberofCorrectAnswers}
of ${questions.length} responses correct) <<<
>>> Status: PASSED <<<`)
}

return grade;
}
}

function runProgram() {
askForName();
// TODO 1.1c: Greet candidate using their name //
console.log();
console.log(`\nHello ${candidateName}, Good-luck testing!`);
askQuestion();
gradeQuiz(this.candidateAnswers);
}

// ----------- Don't write any code or change any code below this line ---------- //
module.exports = {
candidateName: candidateName,
Expand All @@ -58,4 +80,4 @@ module.exports = {
candidateAnswers: candidateAnswers,
gradeQuiz: gradeQuiz,
runProgram: runProgram
};
};
Loading