Skip to content

Instantly share code, notes, and snippets.

@briyithhhh
Created November 26, 2022 00:30
Show Gist options
  • Save briyithhhh/484b4ddf9b6a5ae6b9de03bf78961d7e to your computer and use it in GitHub Desktop.
Save briyithhhh/484b4ddf9b6a5ae6b9de03bf78961d7e to your computer and use it in GitHub Desktop.
rock-paper-scissors game made in JavaScript
function aleatorio(min,max){
var num = Math.floor( Math.random() * (max - min + 1) + min );
return num;
}
var options = prompt('¿Estas listo para jugar?\nLas opciones son:\n0:Piedra\n1:Papel\n2:Tijera\n\n¡Escoge una opción!')
var game = ["Piedra", "Papel", "Tijera"]
function decision(option, optionPC){
console.log(`Option jugador | ${option} \nOptionPC | ${optionPC}`);
if(option === optionPC){
return(`Has elegido ${game[option]} y la máquina también\n¡Es un empate!`)
} else{
switch(true){
case (0 && optionPC==1):
console.log(`Has elegido piedra y la máquina papel\nPerdiste :c`)
break;
case (0 && optionPC==2):
console.log("Has elegido piedra y la máquina tijera\n¡Ganaste!")
break;
case (1 && optionPC==0):
console.log("Has elegido papel y la máquina piedra\n¡Ganaste!");
break;
case (1 && optionPC==2):
console.log("Has elegido papel y la máquina tijera\nPerdiste :c");
break;
case (2 && optionPC==0):
console.log("Has elegido tijera y la máquina piedra\nPerdiste :c");
break;
case (2 && optionPC==1):
console.log("Has elegido tijera y la máquina piedra\n¡Ganaste!");
break;
}
}
}
decision(options, aleatorio(0,2));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment