Javascript: Janken Function
Java, Script, Function, Janken
let userChoice = prompt(
"Do you choose rock, paper or scissors?"
),
computerChoice = Math.random();
computerChoice = computerChoice <= .34 ?
"rock" : computerChoice <= .67 ?
"paper" : "scissors", alert(
"Computer: " + computerChoice
);
const compare = function(o, r) {
return o === r ?
"The result is a tie!" :
"rock" === o ?
"scissors" === r ?
"rock wins" : "paper wins" :
"paper" === o ? "rock" ===
r ? "paper wins" :
"scissors wins" :
"scissors" === o ?
"rock" === r ? "rock wins" :
"scissors wins" : void 0
};
alert(
compare(userChoice, computerChoice)
);