0

PLEASE SOLVED MY PROBLEM!! (SOLVED)

How to check and call all items in array. example: var player= prompt('select one options (rock, scissors, paper)') ; var item = ['rock', 'scissors', 'paper'] ; if(player == item[0] | player == item[1] | player == item[2]) { alert('test') ; } My Question is How to write the code above to make it more concise??? https://code.sololearn.com/WpM35P2Kwdri/?ref=app

24th May 2021, 3:18 PM
hafidz ridwan cahya
hafidz ridwan cahya - avatar
2 Answers
+ 3
You can use includes method if( item.includes(player) ) alert('test');
24th May 2021, 3:53 PM
Aravind Shetty
Aravind Shetty - avatar
+ 2
... if(item.some(a => a == player)) ...
24th May 2021, 3:52 PM
HappyRogue
HappyRogue - avatar