Skip to content

Commit

Permalink
Graded Assignment 1 completed
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Jan 28, 2024
1 parent 859319e commit eeaff4a
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions candidate-testing.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ correctAnswers.push("Sally Ride", "true", "40", "Trajectory", "3");
function askForName() {
// TODO 1.1b: Ask for candidate's name //
candidateName = input.question("Enter your name: ");
console.log();
}

function askQuestion() {
Expand All @@ -30,6 +31,7 @@ function askQuestion() {
for (let i=0; i<questions.length; i++) {
console.log(questions[i]);
candidateAnswers.push(input.question("What is your answer? "));
console.log();
}

}
Expand All @@ -38,20 +40,48 @@ function gradeQuiz(candidateAnswers) {

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

for (let i=0; i<questions.length; i++) {
console.log(`${candidateName}'s response: ${candidateAnswers[i]} Correct answer: ${correctAnswers[i]}`)
}
// for (let i=0; i<questions.length; i++) {
// console.log(`${candidateName}'s response: ${candidateAnswers[i]} Correct answer: ${correctAnswers[i]}`)
// }

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


let numberOfCorrectAnswers = 0;
for (let i = 0; i < questions.length; i++) {
if (candidateAnswers[i].toLowerCase() === correctAnswers[i].toLowerCase()) {
numberOfCorrectAnswers++;
}
}
grade = numberOfCorrectAnswers / questions.length * 100;

console.log();
console.log("-----------------------------------------------------------------------------------");
console.log(`Candidate Name: ${candidateName}`);
console.log();

for (i=0; i<questions.length; i++) {
console.log(`${i+1}) ${questions[i]}`);
console.log(`Your Answer: ${candidateAnswers[i]}`);
console.log(`Correct Answer: ${correctAnswers[i]}`);
console.log();
}

console.log(`>>> Overall Grade: ${grade}% (${numberOfCorrectAnswers} of ${questions.length} responses correct)`);

if (grade >= 80) {
console.log(`>>> PASSED`);
} else {
console.log(`>>> FAILED`);
}
console.log("-----------------------------------------------------------------------------------");

return grade;
}

function runProgram() {
askForName();
// TODO 1.1c: Greet candidate using their name //
console.log("Hello, " + candidateName + ". I hope you are prepared for this quiz!");
console.log("Hello, " + candidateName + "! " + "I hope you are prepared for this quiz!");
console.log();
askQuestion();
gradeQuiz(this.candidateAnswers);
}
Expand Down

0 comments on commit eeaff4a

Please sign in to comment.