-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
66 lines (64 loc) · 2.3 KB
/
script.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
54
55
56
57
58
59
60
61
62
63
64
65
66
let randomNumber = 0;
let numberOfAttempts = 0;
const playgame = document.getElementById('playgame');
let prevGuess = "";
let winner = false;
const initialBoard = document.getElementById('initialBoard');
let audio = new Audio("mixkit-video-game-mystery-alert-234.wav");
let wrongAnswerAudio = new Audio("wrong-38598.mp3");
let correctAnswerAudio = new Audio("good-6081.mp3");
const playBoard = document.getElementById('mainBoard');
const playRandomly = () =>{
let userInput = userValue.value;
audio.pause();
wrongAnswerAudio.pause();
correctAnswerAudio.pause();
userInput.trim();
if(userInput == "" || userInput < 1){
wrongAnswerAudio.play();
choose.innerText = "NO INPUT⚡";
}else if(userInput > randomNumber && !winner){
wrongAnswerAudio.play();
console.log(prevGuess);
++numberOfAttempts;
choose.innerText = "⚡😒NO! YOUR GUESS IS HIGH⚡";
attempts.innerText = numberOfAttempts;
console.log(prevGuess);
allGuess.innerText = prevGuess.concat(`${userInput} `);
userValue.value = "";
}
else if(userInput < randomNumber && !winner){
wrongAnswerAudio.play();
prevGuess.concat(`${userInput} `);
++numberOfAttempts;
choose.innerText = "⚡NO! YOUR GUESS IS LOW🙄";
attempts.innerText = numberOfAttempts;
allGuess.innerText = prevGuess.concat(`${userInput} `);
userValue.value = "";
}
else if(userInput == randomNumber && !winner){
correctAnswerAudio.play();
winner = true;
allGuess.innerText = prevGuess.concat(`${userInput} `);
++numberOfAttempts;
choose.innerText = "Correct!😍😎";
attempts.innerText = numberOfAttempts;
userValue.disabled = true;
newgame.style.display = "block";
}
else{
wrongAnswerAudio.play();
choose.innerText = "Not A Valid Input🤐";
userValue.value = "";
}
}
playgame.addEventListener('click', () => {
audio.play();
initialBoard.style.display = 'none';
playBoard.style.display = 'block';
randomNumber = Math.floor(Math.random()*100);
console.log(randomNumber);
numberOfAttempts = 0;
winner = false;
})
guess.addEventListener('click', playRandomly);