3

I currently have a unique multiple choice test where some of the questions have multiple choice that are all correct. I'm currently trying to write something to check if every answer is question within the choice. choices is prop of type Array which holds multiple choice questions. I want to be able to check that isCorrect is true for each object within this.props.choices. Currently the structure looks like this:

"choices": [
        {
          "text": "Text 1",
          "isCorrect": true,

        },

        {
          "text": "Text 2",
          "isCorrect": true,
        }
  ]
3
  • let me know if that solved your issue or if you need any more help! Commented Jun 8, 2020 at 19:06
  • oh it worked out great! Thank you! Commented Jun 8, 2020 at 23:30
  • Turtlefish can you please mark the answer as correct below to signal to others that this question has been answered. thanks! Commented Jun 10, 2020 at 6:18

1 Answer 1

9

you want to use every on array so like this:

choices.every(choice => choice.isCorrect)

this will return true if all values are true

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.