-
Notifications
You must be signed in to change notification settings - Fork 0
/
scripts.js
81 lines (48 loc) · 1.92 KB
/
scripts.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
81
'use strict';
let num = Math.trunc(Math.random() * 20) + 1;
let jScore = 0;
let jHighScore = 1000;
const displayMessage = function(message) {
document.querySelector('.message').textContent = message;
}
const displayScore = function(score) {
document.querySelector('.score').textContent = score;
}
document.querySelector('.check').addEventListener('click', function() {
const guess = Number(document.querySelector('.guess').value);
console.log(num, guess);
//If there is no guess
if (!guess) {
displayMessage(`🤷♀️No number entered.`);
}
//If guess is incorrect
else if (guess !== num) {
displayMessage(guess < num ? `Wrong guess! Too low.` : `Wrong guess! Too high.`);
jScore++;
document.querySelector('.score').textContent = (jScore);
}
//If guess is correct
else if (guess === num) {
document.querySelector('body').style.backgroundColor = '#60b347';
document.querySelector('.number').style.width = '30rem';
document.querySelector('.number').textContent = num;
displayMessage("🎉Congrats! You guessed it! You beat your high score!");
jHighScore = jScore > jHighScore ? jHighScore : jScore;
document.querySelector('.highscore').textContent = (jHighScore);
}
}
);
document.querySelector('.again').addEventListener('click', function() {
document.querySelector('body').style.backgroundColor = '#222';
num = Math.trunc(Math.random() * 20) + 1;
jScore = 0;
document.querySelector('.number').textContent = '?';
displayScore(``);
displayMessage("Start guessing...");
document.querySelector('.score').textContent = "0";
})
//Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted
//Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Restricted
// function sortNums(a, b) {
// return a > b ? 1 : b > a ? -1 : 0;
// }