Code is working properly but is not passing 11, 12, 13, 14. I’ve been trying to change some things to get it to pass but it has not worked.
const questions = [
{category:"Anatomy",
question:"Besides its use as a sensory apparatus, what is another purpose of the hair on a tarantula's body?",
choices: ['Territory', 'Defense', 'Warmth'],
answer: 'Defense'}
,
{category:"Types",
question:"There are basically two types of these spiders, the 'terrestrial' or ground-dwelling tarantulas and ...?",
choices: ['Aboreal', 'Old World', 'New World'],
answer: 'Aboreal'}
,
{category:"Climate",
question:"Tarantulas are capable of surviving in all but ...?",
choices: [ 'Desert', 'Arctic', 'Tropical'],
answer: 'Arctic'}
,
{category:"Lifespan",
question:"Female tarantulas are blessed with a lifespan that is longer than most arachnoid species. About how long can one live under ideal conditions?",
choices: ['10-15 years', 'up to 20 years', '20+ years'],
answer: '20+ years'}
,
{category:"Hunting",
question:"How do tarantulas find their food?",
choices: ['Sound', 'Smell', 'Vibrations'],
answer: 'Vibrations'}
]
function getRandomQuestion(questions) {
let randomNum = Math.floor(Math.random() * questions.length);
{return questions[randomNum]};
}
function getRandomComputerChoice(choices) {
let randomIndex = Math.floor(Math.random() * choices.length);
{return choices[randomIndex]};
}
function getResults(key, computerChoice) {
if (computerChoice === key){ return "The computer's choice is correct!";
} else {
return `The computer's choice is wrong. The correct answer is: ${key}`;
}
};
let selectedQuestObject = getRandomQuestion(questions);
let availableChoices = selectedQuestObject.choices;
let key = selectedQuestObject.answer;
let computerChoice = getRandomComputerChoice(availableChoices);
let grade = getResults(key, computerChoice);
let question = selectedQuestObject.question;
console.log("Question:", question);
console.log("Computer chose:", computerChoice);
console.log("Grade:", grade);
- I thought I was passing getResult parameters correctly with questionObject first and computerChoice second. with getResults(key, computerChoice) & let key = selectedQuestObject.answer
- It is comparing and returning when it is incorrect, correctly.
- It is comparing and returning when it is correct, correctly.
- (computerChoice === key) used for comparison.
-
11. Your
getResultsfunction should take the question object as the first parameter and the computer’s choice as the second parameter. -
Failed:12. If the computer choice matches the answer,
getResultsshould returnThe computer's choice is correct! -
Failed:13. If the computer choice doesn’t match the answer,
getResultsshould returnThe computer's choice is wrong. The correct answer is: <correct-answer>, where<correct-answer>is the value of the correct answer to the chosen question. -
Failed:14. Your
getResultsfunction should use exact equality comparison, not substring matching.
