Quotes help make search much faster. Example: "Practice Makes Perfect"

Saturday, December 8, 2012

Codecademy: Codeyear One Round of Rock, Paper, Scissors Introduction


//sample solution


var userchoice = prompt("Choose rock, paper, or scissors:");
console.log("User chooses "+userchoice);
var choices = ["rock","paper","scissors"];
function compchoice(choices){
var choiceIndex = Math.floor(Math.random()*3);
return choices[choiceIndex];
}
var cpuchoice = compchoice(choices);
console.log("Computer chooses "+cpuchoice);
if(userchoice === cpuchoice){
console.log("It's a tie!");
} else if((userchoice === 'paper' && cpuchoice === 'rock')||(userchoice === 'rock' && cpuchoice === 'scissors')||(userchoice === 'scissors' && cpuchoice === 'paper')) {
console.log("User wins!");
} else {
console.log("Computer wins!");
}

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts