const options = [ "rock", "scissors", "paper" ];
do {
let input = window.prompt(options.map((option, idx) => "enter " + idx + " for " + option).join(", "));
if (typeof input === "string") {
input = input.replace(/[^0-9]/g, "");
if (options[input]) {
window.alert("You picked " + options[input] + "!");
const computer_choice = ~~(Math.random() * options.length);
window.alert("The computer picked " + options[computer_choice] + "!");
let you_beat = input + 1, computer_beats = computer_choice + 1;
if (you_beat > options.length) {
you_beat = 0;
}
if (computer_beats > options.length) {
computer_beats = 0;
}
if (you_beat === computer_choice) {
window.alert("You win! :D");
} else if (computer_beats === input) {
window.alert("You loose... :(");
} else {
window.alert("It was a tie! :|");
}
} else {
window.alert("Oh no! You didn't enter a number...");
}
} else {
window.alert("Woops! You didn't enter anything or your input was not in the correct format...");
}
} while (window.confirm("Play again?"));