0

so I've got a quiz like carousel here. But it isn't quite working yet. The user has the possibility to either answer yes or no on four questions. Then I'm pushing the answer to an empty array and I've got an array with the correct answers like this:

var antwoorden = ['ja', 'nee', 'nee', 'ja'];
var gebruikerant = [];

So the user his answer gets pushed into the array "gebruikerant" by giving the buttons 'click' eventlistener.

And after the answers have been given I'd like to console log the result.

Any help will be highly appreciated!

Ryan
  • 21
  • 4
  • If you need to see if they are _the exact same array/object_ then you can use strict equality `===`. But it looks like for your case, you just need check for equal _value_ of two different arrays-- if that's the case, the link provided by Obsidian Age is your best bet-- basically to do it you need to iterate over each value and check for equality between each entry-- and if the entry is itself an array or object, you'll probably need to recurse... – Alexander Nied Mar 26 '18 at 22:01
  • arrays of strings (and most numbers) can be simply compared as strings: `String(a1) == String(a2)`. – dandavis Mar 26 '18 at 22:25

1 Answers1

0

You could maybe use reduce() like so:

var isSame = gebruikerant.reduce((acc,antwoord,idx)=>antwoorden[idx]==antwoord);
TLP
  • 1,262
  • 1
  • 8
  • 20