Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Main #8

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
69 changes: 39 additions & 30 deletions candidate-testing.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,70 @@
const input = require('readline-sync');

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

// TODO 1.1a: Define candidateName //
// TODO 1.1a: Define candidateName //
let candidateName;

// TODO 1.2a: Define question, correctAnswer, and candidateAnswer //
let question;
let correctAnswer;
let candidateAnswer;


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

let questions = [
"Who's Michael Jackson'?",
"True or false: 1000 miles = 5 kilometers.",
"How old am I?",
'Given the array [8, "Orbit", "Trajectory", 45], what entry is at index 2?',
"How many people live in my house?"
];

let correctAnswers = [
"Singer",
"false",
"25",
"Trajectory",
"2"
];

let candidateAnswers = [];

function askForName() {
// TODO 1.1b: Ask for candidate's name //

candidateName = input.question("What is your name? ");
}

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


for (let i = 0; i < questions.length; i++) {
candidateAnswer = input.question(questions[i] + " ");
candidateAnswers.push(candidateAnswer);
console.log(`Your Answer: ${candidateAnswer}\nCorrect Answer: ${correctAnswers[i]}\n`);
console.log(); // Add a line break
}
}

function gradeQuiz(candidateAnswers) {
// TODO 1.2c: Let the candidate know if they have answered the question correctly or incorrectly //
let correctCount = 0;

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


for (let i = 0; i < candidateAnswers.length; i++) {
if (candidateAnswers[i].toLowerCase() === correctAnswers[i].toLowerCase()) {
correctCount++;
}
}

let grade; //TODO 3.2 use this variable to calculate the candidates score.
let grade = (correctCount / questions.length) * 100;

console.log(`>>> Overall Grade: ${grade}% (${correctCount} of ${questions.length} responses correct) <<<`);
console.log(grade >= 80 ? ">>> Status: PASSED <<<" : ">>> Status: FAILED <<<");

return grade;
}

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

// ----------- Don't write any code or change any code below this line ---------- //
module.exports = {
candidateName: candidateName,
question: question,
correctAnswer: correctAnswer,
candidateAnswer: candidateAnswer,
questions: questions,
correctAnswers: correctAnswers,
candidateAnswers: candidateAnswers,
gradeQuiz: gradeQuiz,
runProgram: runProgram
};
runProgram();
Loading