-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
84 lines (76 loc) · 3.63 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//practica con if
function juegoVsPlayer2() {
var player1 = prompt("Player 1: Ingresa piedra, papel o tijera");
var player2 = prompt("Player 2: Ingresa piedra, papel o tijera");
if (player1 == "piedra" && player2 == "tijera" || player1 == "tijera" && player2 == "papel" || player1 ==
"papel" && player2 == "piedra") {
alert("Gano Player1 !!! - Player1: " + player1 + " - Player2: " + player2)
} else if (player2 == "piedra" && player1 == "tijera" || player2 == "tijera" && player1 == "papel" || player2 ==
"papel" && player1 == "piedra") {
alert("Gano Player2 !!! - Player1: " + player1 + " - Player2: " + player2)
} else if (player1 == "piedra" && player2 == "piedra" || player1 == "tijera" && player2 == "tijera" ||
player1 == "papel" && player2 == "papel") {
alert("Empataron! Ninguno gano xD - Player1: " + player1 + " - Player2: " + player2)
} else {
alert("Alguien escribio algo mal :6 - Player1 escribio:" + player1 + " - Player2 escribio:" + player2)
}
}
function jugadaCpu() {
var opcion = ["piedra", "papel", "tijera"];
var numero = Math.floor(Math.random() * 3)
return opcion[numero];
}
//practica con if
function JuegoVsPcIf() {
var miJugada = prompt("Player 1: Ingresa piedra, papel o tijera");
var cpu = jugadaCpu();
if (miJugada == "piedra" && cpu == "tijera" || miJugada == "tijera" && cpu == "papel" || miJugada == "papel" &&
cpu == "piedra") {
alert("Gane yo !" + "Mi jugada: " + miJugada + "CPU: " + cpu)
} else if (cpu == "piedra" && miJugada == "tijera" || cpu == "tijera" && miJugada == "papel" || cpu ==
"papel" && miJugada == "piedra") {
alert("Gano cpu !" + "Mi jugada: " + miJugada + "CPU: " + cpu)
} else if (miJugada == "piedra" && cpu == "piedra" || miJugada == "tijera" && cpu == "tijera" || miJugada ==
"papel" && cpu == "papel") {
alert("Empataron! Ninguno gano xD " + "Mi jugada: " + miJugada + "CPU: " + cpu)
} else {
alert("Esta opcion no es valida :6" + "Yo escribi:" + miJugada + " - cpu dijo:" + cpu)
}
}
//practica con switch
function JuegoVsPcSwitch() {
var player1 = prompt("Player 1: Ingresa piedra, papel o tijera");
var cpu = jugadaCpu();
switch (player1) {
case "piedra":
if (cpu == "papel") {
alert("Gano cpu !" + "<br>" + "PLayer1: " + player1 + "CPU: " + cpu)
} else if (cpu == "tijera") {
alert("Gano Player1 !" + "<br>" + "PLayer1: " + player1 + "CPU: " + cpu)
} else {
alert("Empataron! Ninguno gano xD " + "Player1: " + player1 + "CPU: " + cpu)
}
break;
case "papel":
if (cpu == "tijera") {
alert("Gano cpu !" + "<br>" + "PLayer1: " + player1 + "CPU: " + cpu)
} else if (cpu == "piedra") {
alert("Gano Player1 !" + "<br>" + "PLayer1: " + player1 + "CPU: " + cpu)
} else {
alert("Empataron! Ninguno gano xD " + "Player1: " + player1 + "CPU: " + cpu)
}
break;
case "tijera":
if (cpu == "piedra") {
alert("Gano cpu !" + "<br>" + "PLayer1: " + player1 + "CPU: " + cpu)
} else if (cpu == "papel") {
alert("Gano Player1 !" + "<br>" + "PLayer1: " + player1 + "CPU: " + cpu)
} else {
alert("Empataron! Ninguno gano xD " + "Player1: " + player1 + "CPU: " + cpu)
}
break;
default:
alert("Esta opcion no es valida :6 - " + "<br>" + "PLayer1 escribio:" + player1 + " - cpu escribio:" +
cpu)
}
}