How would I write a function that takes two arguments (the array responses
and a string
), and for the isEssayQuestion
s that are true, compares the string
parameter to the response
key value and returns true
if they match anyone and false
if it doesn't match any.
const responses = [
{
question: 'What is the phase where chromosomes line up in mitosis?',
response: 'Metaphase',
isCorrect: true,
isEssayQuestion: false
},
{
question: 'What anatomical structure connects the stomach to the mouth?',
response: 'Esophagus',
isCorrect: true,
isEssayQuestion: false
},
{
question: 'What are lysosomes?',
response: 'A lysosome is a membrane-bound organelle found in many animal cells. They are spherical vesicles that contain hydrolytic enzymes that can break down many kinds of biomolecules.',
isCorrect: true,
isEssayQuestion: true
},
{
question: 'True or False: Prostaglandins can only constrict blood vessels.',
response: 'True',
isCorrect: false,
isEssayQuestion: false
}
];
// example
checkForPlagiarism(responses, 'spherical vesicles that contain hydrolytic enzymes'); //> true
checkForPlagiarism(responses, 'this string does not appear in the responses'); //> false
// my code
function checkForPlagiarism(test, answerKey) {
for (let i = 0; i < test.length; i++) {
let question = test[i];
if (question.isEssayQuestion) {
let response = question.response;
return response.includes(answerKey);
}
}
}