Sinbad Konick

Rock, Paper, Scissor with computer choice – javaScript Code

This is done by using the Math.random() function in javaScript. If you look at the code you will understand it easily.
Math.random() variable will equal to a number between 0 to 1. 

Please make sure you align and indent the code after you copy.

var userChoice = prompt(“Do you choose rock, paper or scissors?”);

var computerChoice = Math.random();
if (computerChoice < 0.34)
{
computerChoice = “rock”;
}
else if(computerChoice <= 0.67)
{
computerChoice = “paper”;
}
else
{
computerChoice = “scissors”;
} read more