Question

I'm making a JQuery slot machine game and I'm having difficulty comparing three images(indexes) I store...

I'm making a JQuery slot machine game and I'm having difficulty comparing three images(indexes)

I store images paths as strings in an array, and use a random number from 0 to arr.length to get a random image.

When the three indexes are equal to each other, I should get an alert saying I won, and try again if they are not equal.

here is what I tried, and is not working:

if( (myRandNums[0] === myRandNums[1]) && (myRandNums[0] === myRandNums[2]) ){
           $('#alert').text("Congratulations! You won!");
       }
       else{
           $('#alert').text("You lost, spin again");
       }

Homework Answers

Answer #1

if( (myRandNums[0] === myRandNums[1]) && (myRandNums[0] === myRandNums[2]) ){
windows.alert("Congratulations! You won!");
       }
       else{
windows.alert("You lost, spin again");
       }

or

if( (myRandNums[0] === myRandNums[1]) || (myRandNums[0] === myRandNums[2]) ){
windows.alert("Congratulations! You won!");
       }
       else{
windows.alert("You lost, spin again");
       }

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT