-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
54 lines (40 loc) · 1.37 KB
/
main.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
"use strict";
const userNumber = document.querySelector(".js-input");
const button = document.querySelector(".js-button");
const clue = document.querySelector(".js-clue");
const attempt = document.querySelector(".js-try");
const max = 100;
function getRandomNumber(max) {
return Math.ceil(Math.random() * max);
}
let randomNumber = getRandomNumber(max);
console.log(randomNumber);
function checkUserNumber(event){
let userNumberValue = parseInt(userNumber.value);
console.log(userNumberValue);
// event.preventDefault();
if (userNumberValue === randomNumber){
clue.innerHTML = "Has ganado campeona";
console.log("has ganado");
} else if (userNumberValue < 0){
clue.innerHTML = "El número debe estar entre 0 y 100";
} else if (userNumberValue < randomNumber){
clue.innerHTML = "Demasiado bajo";
} else if (userNumberValue > max){
clue.innerHTML = "El número debe estar entre 0 y 100";
} else if (userNumberValue > randomNumber){
clue.innerHTML = "Demasiado alto";
}
}
let numberOfClicks = 0;
function numberOfAttemps(){
numberOfClicks++;
attempt.innerHTML = `Número de intentos: ${numberOfClicks}`;
}
function allFunctions(event) {
event.preventDefault();
checkUserNumber();
numberOfAttemps();
}
button.addEventListener("click",allFunctions);
console.log("pista");