Assignment #1: Candidate Testing¶
OK, staff, we received many applications for our astronaut training program, and we need to do an initial evaluation of the candidates. Management needs you to create a quick quiz to help select the best candidates.
The requirements below are what your END assignment will look like. This assignment is broken down so you can complete small pieces as you go. You need to move sequentially starting at Part 1. Please read the WHOLE assignment page before starting.
Ask the candidate (user) to enter their name
Use a loop to ask five questions, one at a time, to the candidate
Collect the candidate's answers
Check those answers for accuracy (case insensitive equality check)
Calculate the candidate's overall percentage
Determine if the candidate did well enough to enter our program (need >= 80% to pass)
Display the results.
Take It Step by Step¶
When starting any project, it's best to approach it as a series of smaller, testable parts. The goal is to get simple parts working first and then expand the code in a systematic way. The following is NOT the only way to complete this assignment, but it provides a framework for thinking through the project.
Get the Starter Code¶
Fork this replit.
Part 1: Minimum Viable Quiz¶
Ask for the candidate's name. Look for
TODO 1.1ain the starter code. On the line below this TODO comment, define a variable called
candidateNamewith an initial value of the empty string.
TODO 1.1b. Inside of the function
askForName(), write code asking the user to enter their name into the program and store the value as
TODO 1.1c. Underneath it, write a message to the console greeting the user using the name they just provided.
1.2 Single Question Quiz¶
Ask the user to answer a single quiz question. Look for
TODO 1.2a. Below the TODO comment, define variables called
questionshould be initialized to the following string:
"Who was the first American woman in space? ".
Note the trailing space at the end of this string is required.
correctAnswershould be initialized to
candidateAnswerwill initially be set to the empty string.
TODO 1.2b. Using your question variable, display the question and prompt the candidate for their answer. Store their response in one of the variables you defined just above.
TODO 1.2c, check the candidate's answer to see if it is correct. Provide basic feedback to the candidate, letting them know if their answer is correct or not.
Make sure your small app works properly before moving on to part 2.
Part 2: Multiple Questions¶
Now that your small app is working, expand it to deal with multiple questions.
This time, you only have one
TODO item in the starter code. You will need
to determine which lines need to be modified.
correctAnswersvariables as arrays. Use the table below to fill these arrays.
Replace your code from
TODO 1.2bwith a loop that programmatically asks each question in the array and stores the user's responses.
Replace the basic feedback from
TODO 1.2cwith a template literal that displays each of the candidate's responses in addition to the corresponding correct answers.
Who was the first American woman in space?
True or false: 5 kilometer == 5000 meters?
(5 + 3)/2 * 10 = ?
Given the array
What is the minimum crew size for the ISS?
Keep the questions and correct answers stored in this exact order.
Part 3: Grade the Quiz¶
Finally, calculate the candidate's score and print the results. There are no
TODOs in this section,
just be sure to only modify code that you have written, or add code. Don't remove anything in the file
that you haven't written. Doing so may cause your program to behave unexpectedly - and we might not be able to grade it!
Your task here is to:
Compare the candidate answers with the correct answers,
Calculate the candidate's score as a percentage,
Convey to the candidate if they have passed the quiz with an 80% or if they have failed.
Checking for the correct answer should be case insensitive (e.g. "Orbit" is the same as "orbit").
TODO 1.2cyou should see a variable declaration for
grade. Use this to calculate the candidate's score.
To calculate the candidate's percentage, use the equation:
(Number of Correct Answers) / (Number of Quiz Questions) * 100
The results output should include the candidate's name, the candidate's responses, the correct answers, the final percentage, and if the candidate passed the quiz.
Candidate Name: Can Twin 1) Who was the first American woman in space? Your Answer: sally ride Correct Answer: Sally Ride 2) True or false: 5000 meters = 5 kilometers. Your Answer: false Correct Answer: true 3) (5 + 3)/2 * 10 = ? Your Answer: 45 Correct Answer: 40 4) Given the array [8, "Orbit", "Trajectory", 45], what entry is at index 2? Your Answer: trajectory Correct Answer: Trajectory 5) What is the minimum crew size for the ISS? Your Answer: 10 Correct Answer: 3 >>> Overall Grade: 40% (2 of 5 responses correct) <<< >>> Status: FAILED <<<
The output will vary slightly based on the candidate's answers to each question.