Created
May 19, 2021 18:17
-
-
Save adrianalonso/7a5365bf5b746a191cbaf00e5b52c302 to your computer and use it in GitHub Desktop.
Revisions
-
adrianalonso created this gist
May 19, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <link href="style.css" rel="stylesheet" /> </head> <body> <h1>Piedra papel o tijera</h1> <section class="choices"> <img class="piedra" src="images/piedra.jpeg" /> <img class="papel" src="images/papel.jpeg" /> <img class="tijeras" src="images/tijeras.jpeg" /> <p id="resultado"></p> </section> <script src="index.js"></script> </body> </html> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ const choices = ["piedra", "papel", "tijeras"]; const uiChoices = document.querySelectorAll(".choices img"); const resultado = document.querySelector("#resultado"); uiChoices.forEach((choice) => { choice.addEventListener("click", () => jugar(choice.className)); }); function jugar(choice) { const contrincanteNumeroAleatorio = parseInt(Math.random() * choices.length); const contricante = choices[contrincanteNumeroAleatorio]; let ganado = -1; if ( (contricante === "piedra" && choice === "papel") || (contricante === "papel" && choice === "tijeras") || (contricante === "tijeras" && choice === "piedra") ) { ganado = 1; } if (contricante === choice) { ganado = 0; } if (ganado > 0) { resultado.textContent = "El contrincante ha elegido " + contricante + " HAS GANADO"; } else if (ganado < 0) { resultado.textContent = "El contrincante ha elegido " + contricante + " HAS PERDIDO"; } else { resultado.textContent = "EMPATE"; } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ .choices img { max-width: 200px; }