From 1e1c83a0da684200376b1b1541d2972dae3e4ee3 Mon Sep 17 00:00:00 2001 From: emervzla Date: Thu, 16 Nov 2023 01:43:44 -0430 Subject: [PATCH] sustitucion de variables ENUM --- script.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/script.js b/script.js index b7c69b9..84f0d32 100644 --- a/script.js +++ b/script.js @@ -5,12 +5,18 @@ const machineScore = document.querySelector("#machine-score") let humanScoreNumber = 0 let machineScoreNumber = 0 +const GAME_OPTIONS = { + ROCK: "rock", + PAPER: "paper", + SCISSORS: "scissors" +} + const playHuman = (humanChoise) => { playTheGame (humanChoise, playMachine()) } const playMachine = () => { - const choises = ["rock", "paper", "scissors"] + const choises = [GAME_OPTIONS.ROCK, GAME_OPTIONS.PAPER, GAME_OPTIONS.SCISSORS] const randomNumber = Math.floor(Math.random() * 3) return choises[randomNumber] @@ -23,9 +29,9 @@ const playTheGame = (human, machine) => { result.innerHTML = "Deu empate!" } - else if ((human === "paper" && machine === "rock") || - (human === "rock" && machine === "scissors") || - (human === "scissors" && machine === "paper")) { + else if ((human === GAME_OPTIONS.PAPER && machine === GAME_OPTIONS.ROCK) || + (human === GAME_OPTIONS.ROCK && machine === GAME_OPTIONS.SCISSORS) || + (human === GAME_OPTIONS.SCISSORS && machine === GAME_OPTIONS.PAPER)) { humanScoreNumber++ humanScore.innerHTML = humanScoreNumber