0

This is what I am trying to achieve: If a input image is clicked, and the input image matches word (referenced in array) run a previously ran function again.

I've messed around with the code but can not seem to figure out why it's not working.

I'm new enough to javascript so please excuse that lack of knowledge and terminology :P

user3594463
  • 123
  • 1
  • 3
  • 12

1 Answers1

2

You need to use array.indexOf(element)

Checkout this question

How do I check if an array includes an object in JavaScript?

Update: for your case yo better use array.some

randomwodrz.some(function(item){return item.word === 'word_to_match'})
Community
  • 1
  • 1
Katya Pavlenko
  • 3,303
  • 3
  • 16
  • 28
  • so do you mean if I used: randomwordz.indexOf('randoms.word' == 'randoms.image') @KaterinaTort – user3594463 May 10 '15 at 15:47
  • updated answer. i kept in mind that you always have some static word that clicked image should match – Katya Pavlenko May 10 '15 at 15:53
  • Thanks a million Katerina for the help, I'm still very confused, I've tried the updated code using array.some but this still won't work. If the image is clicked that matches with the random word displayed on my page I want to run a new function, is there a simpler way?:) – user3594463 May 10 '15 at 16:03
  • ok, i can help you better if you attach a half-working codepen with what you have already done) – Katya Pavlenko May 10 '15 at 16:04