// 1. Get user's choice.
// USER: Rock 0; Paper 1; Scissors 2;
// COMPUTER: Rock 0; Paper 1; Scissors 2;
function getUserChoice(){
const choices = ['rock', 'paper', 'scissors'];
const userChoice = Math.floor(Math.random(choices) * 3);
console.log(userChoice);
}
getUserChoice();
// 2. Get computer's choice.
function getComputerChoice(){
const choices = ['rock', 'paper', 'scissors'];
const computerChoice = Math.floor(Math.random(choices) * 3);
console.log(computerChoice);
}
getComputerChoice();
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter