-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
41 lines (35 loc) · 1.25 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
function getRandomNumber(max) {
return Math.ceil(Math.random() * max);
}
const randomNumber = getRandomNumber(100);
console.log(randomNumber);
function resultMessage() {
const input = document.querySelector('#tryNumber');
const message = document.querySelector(".message");
const inputValue = parseInt(input.value);
console.log(inputValue, randomNumber);
if(inputValue < randomNumber) {
message.innerHTML = "Demasiado bajo";
}
else if(inputValue > randomNumber) {
message.innerHTML = "Demasiado alto";
}
else if(inputValue = randomNumber) {
message.innerHTML = "Has ganado campeona!!"
}
else if(inputValue === NaN || inputValue > 100 || inputValue < 1) {
message.innerHTML = "El número debe estar entre 1 y 100"
}
}
let attemptsNumberOp = 0;
function attemptsCount() {
attemptsNumberOp += 1;
const attemptsNumber = document.querySelector(".attempts_number");
attemptsNumber.innerHTML = attemptsNumberOp; //aquí estaba fallando que tenía puesto +=
}
function handleResult (){
resultMessage();
attemptsCount();
}
const clickbutton = document.querySelector(".button");
clickbutton.addEventListener("click", handleResult);