Paper , Sissors , Rock game


#1

My code below :

var gamechoice=["Rock","Scissors","Papers"]

var userchoice = prompt("Please enter Rock , Scissors or Papers");

var computerchoice = gamechoice[rand];
var rand = Math.floor(Math.random()*gamechoice.length);

if(userchoice == computerchoice){
console.log("You"+" : "+ userchoice);
console.log("Computer"+" : "+ computerchoice);
console.log("Tie the game");
}else if(userchoice == "Rock" && computerchoice == "Scissors"){
console.log("You : Rock");
console.log("Computer : Scissors ");
console.log("You are winner!");
}else if( userchoice == "Rock" && computerchoice == "Papers"){ console.log("You : Rock");
console.log("Computer : Papers ");
console.log("You are loser!");
}else if( userchoice == "Scissors" && computerchoice == "Rock"){
console.log("You : Scissors");
console.log("Computer : Rock ");
console.log("You are loser!");
}else if( userchoice == "Scissors" && computerchoice == "Papers"){
console.log("You : Scissors");
console.log("Computer : Papers ");
console.log("You are winner!");
}else if( userchoice == "Papers" && computerchoice == "Scissors"){
console.log("You : Papers");
console.log("Computer : Scissors ");
console.log("You are loser!");
}else if( userchoice == "Papers" && computerchoice == "Rock"){
console.log("You : Papers");
console.log("Computer : Rock ");
console.log("You are winner!");
}else{
console.log("You have to enter Rock , Scissors or Papers");}

This code can work , but it's too complex.
Can use "function" on this code?


#2

Hi by

Can use "function" on this code?

Do you aske if you Can do this code with a function?
if so yes ... Just follow The instruction of The lesson.


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.