-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
80 lines (71 loc) · 2.54 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
let computerGuess;
let userGuess = [];
let userGuessUpdate = document.getElementById('textOutput');
let userNumberUpdate = document.getElementById('inputBox');
let audio = new Audio('Image/move.mp3');
const init = () => {
computerGuess = Math.floor(Math.random() * 100);
document.getElementById("newGameButton").style.display = "none";
document.getElementById("gameArea").style.display = "none";
document.querySelector("body").style.display = "flex";
};
const startGame = () => {
document.getElementById("welcomeScreen").style.display = "none";
document.getElementById("gameArea").style.display = "block";
}
// Reload the page
const newGameBegin = () => {
audio.play();
window.location.reload();
}
// Start New Game
const startNewGame = () => {
document.getElementById("newGameButton").style.display = "inline";
userNumberUpdate.setAttribute('disabled', true);
}
// Main logic of our app
const compareGuess = () => {
audio.play();
const userNumber = Number(document.getElementById('inputBox').value);
userGuess = [...userGuess, userNumber];
document.getElementById('guesses').innerHTML = userGuess;
// Check the value is low or high
if (userGuess.length < maxGuess) {
if (userNumber > computerGuess) {
userGuessUpdate.innerHTML = "Your guess is High 😲";
userNumberUpdate.value = "";
} else if (userNumber < computerGuess) {
userGuessUpdate.innerHTML = "Your guess is Low 😔";
userNumberUpdate.value = "";
} else {
userGuessUpdate.innerHTML = "It's Correct 😄";
userNumberUpdate.value = "";
startNewGame();
}
} else {
if (userNumber > computerGuess) {
userGuessUpdate.innerHTML = "You Loose!! Correct number was " + computerGuess;
userNumberUpdate.value = "";
startNewGame();
} else if (userNumber < computerGuess) {
userGuessUpdate.innerHTML = "You Loose!! Correct number was " + computerGuess;
userNumberUpdate.value = "";
startNewGame();
} else {
userGuessUpdate.innerHTML = "It's Correct 😄";
userNumberUpdate.value = "";
startNewGame();
}
}
document.getElementById('attempts').innerHTML = userGuess.length;
};
const easyMode = () => {
audio.play();
maxGuess = 10;
startGame();
}
const hardMode = () => {
audio.play();
maxGuess = 5;
startGame();
}