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

1 Answer 1

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'})
Sign up to request clarification or add additional context in comments.

4 Comments

so do you mean if I used: randomwordz.indexOf('randoms.word' == 'randoms.image') @KaterinaTort
updated answer. i kept in mind that you always have some static word that clicked image should match
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?:)
ok, i can help you better if you attach a half-working codepen with what you have already done)

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.