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");
}
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");
}
Get Answers For Free
Most questions answered within 1 hours.