
Santiago Pérez
Preguntastudent•hace 3 años
hola cuando entro a la pagina el juego solo se repite pocas veces y se sale la alerta me podrian ayudar?
<!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <title>Piera, papel o tijera</title> <script> function aleatorio(min, max){ return Math.floor( Math.random() * (max - min + 1) + min) } function eleccion(jugada) { let resultado = "" if(jugada == 1) { resultado = "piedra🥌" } else if(jugada == 2) { resultado ="papel 🧻" } else if(jugada == 3){ resultado = "tijera ✂" } else { resultado = "MAL ELEGIDO" } return resultado } // 1 es piedra, 2 es papel, 3 es tijera let jugador = 0 let pc = 0 let triunfos = 0 let perdidas = 0 while (triunfos < 3 && perdidas < 3 ) { pc = aleatorio(1,3) jugador = prompt("elige: 1 piedra, 2 papel, 3 tijera") //alert("elegiste " + jugador) alert("tu elijes: " + eleccion(jugador)) alert("PC elige: " + eleccion(pc)) //COMBATE if(pc == jugador) { alert("empate") } else if(jugador == 1 && pc == 3){ alert("ganaste") triunfo = triunfo + 1 } else if(jugador == 2 && pc == 1){ alert("ganaste") triunfo = triunfo + 1 } else if(jugador == 3 && pc == 2){ alert("ganaste") triunfo = triunfo + 1 } else { alert("perdiste") perdidas = perdidas + 1 } } alert("ganaste " + triunfo + " veces. perdiste " + perdidas + " veces") </script> </head> <body> <h1>piedra, papel o tijera</h1> </body> </html>

Santiago Pérez
student•hace 3 años
muchas gracias andres llevaba como 30 minutos buscando el error, gracias 👍😎

Pedro Andrés Chaparro Quintero
student•hace 3 años
Hola, en el último
alert
else if