-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.js
43 lines (33 loc) · 1.36 KB
/
game.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
let target;
const humanGuessInput = document.getElementById('human-guess');
const computerGuessInput = document.getElementById('computer-guess');
const guessButton = document.getElementById('guess');
const nextRoundButton = document.getElementById('next-round');
$(document).ready(function(){
$('#human-guess').mask('0000');
});
guessButton.addEventListener('click', () => {
// Generate the target value
target = generateTarget();
// Retrieve the player's guess
const currentHumanGuess = humanGuessInput.value;
//
const currentComputerGuess = computerGuessInput.value;
// Make a random 'computer guess'
const computerGuess = Math.floor(Math.random() * 10);
// Determine if the human or computer wins:
const humanIsWinner = compareGuesses(currentHumanGuess, currentComputerGuess, target)
const winner = humanIsWinner ? 'human' : 'computer'
// Set the correct disabled state for the buttons
guessButton.setAttribute('disabled', true)
nextRoundButton.removeAttribute('disabled');
});
nextRoundButton.addEventListener('click', () => {
// Set the correct disabled state for the buttons
nextRoundButton.setAttribute('disabled', true);
guessButton.removeAttribute('disabled');
// Reset the guess input box and the target number display:
guessButton.innerText = 'Calcular';
humanGuessInput.value = '';
computerGuessInput.value = '';
});