I can't figure out this problem :(

I’m looking to write a function that returns the value of isCorrect.

const submissions = [
  {
    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
];

so far I’m stuck on this

function countCorrectQuestions(submissions){
let correctAnswers = 0
for (i=0; i <submissions.length; i++){
correctAnswers +=1
}
return correctAnswers
}

don’t you get an error? your forgot to close the object (}) of your last question
`

that was a copy paste. I didn’t get an error on that.

if you copy paste something, how can that go wrong?

When you call your function, what do you get then? What problem do you experience?

:x: Prompt 1 is not passing test. Received 2
but expected 4
Function called like so: countCorrectQuestions(submissions)

:x: Prompt 1 is not passing test. Received 1
but expected 5
Function called like so: countCorrectQuestions(other submissions)

:x: Prompt 1 is not passing test. Received 2
but expected 4
Function called like so: countCorrectQuestions(submissions)

:white_check_mark: Prompt 1 is passing!

ReferenceError: filterQuestionsByType is not defined
at Object. (/home/runner/Take-Home-Science-Quiz-8/index.test.js:154:3)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Object.Module._extensions…js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
at Module.require (internal/modules/cjs/loader.js:1025:19)
at /home/runner/Take-Home-Science-Quiz-8/index.js:48:1
at Script.runInContext (vm.js:130:18)
at Object. (/run_dir/interp.js:156:20)

what about filterQuestionsByType? shouldn’t you write that function as well? Can I gain access to assignment as well?

Including this kind of information from the beginning saves a lot of time.

1 Like

function countCorrectQuestions(submissions){
let correctAnswers = 0
for (i=0; i <submissions.length; i++){
if (submissions[i].isCorrect) {
correctAnswers ++
}
}
return correctAnswers
}

got it