Posts

Showing posts from January 22, 2019

More efficient choice comparison for Rock Paper Scissors

Image
up vote 9 down vote favorite This is an ongoing school project that I would like to improve. The point is to make the code as efficient (or short) as possible. I would like to reduce it by finding an alternative to all the else ifs when comparing the computer's choice with the user's choice. Here is the code: let weapons = ["Rock", "Paper", "Scissors"]; let random = Math.floor(Math.random()*3); let chosenOne = weapons[random]; let rps = prompt("Welcome to Rock, Paper, Scissors. Would you like to play?" + 'n' + "If you do, enter number 1." + 'n' + "If you don't, enter number 2."); if (rps === "1") { alert("Remember:" + 'n' + " - Rock beats the scissors" + 'n' + " - Paper beat