-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
68 lines (55 loc) · 2.14 KB
/
script.js
File metadata and controls
68 lines (55 loc) · 2.14 KB
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
// console.log('Hello')
var luckyNumber = Math.floor(Math.random()*20);
console.log(luckyNumber);
var score = 20;
var highScore = 0;
var userGuess = document.getElementById('guessing');
var checkbtn = document.getElementById('check');
var mainSection = document.getElementById('main');
var marker = document.getElementById('marker');
var message = document.getElementById('message');
var scoreSection = document.getElementById('score');
var highsc = document.getElementById('highscore');
var againbtn = document.getElementById('again');
function checkYourGuess() {
var guessedNumber = parseInt(userGuess.value);
console.log(guessedNumber);
if(guessedNumber>20 || guessedNumber<1){
console.log('Please guess a number between 1 and 20');
} else {
if(guessedNumber==luckyNumber){
mainSection.style.backgroundColor = '#009933';
console.log('You Won !!!');
marker.innerText = '😎';
message.innerText = 'You Won !!!'
if(highScore<score) {
highScore = score;
highsc.innerText = highScore;
}
} else if(guessedNumber<luckyNumber) {
console.log('Too Low');
mainSection.style.backgroundColor = '#cc0000';
marker.innerText = '😫';
score--;
scoreSection.innerText = score;
message.innerText = 'Your Guess is Too Low, guess higher';
} else if(guessedNumber>luckyNumber){
console.log('Too High');
mainSection.style.backgroundColor = '#cc3300';
marker.innerText = '😫';
score--;
scoreSection.innerText = score;
message.innerText = 'Your Guess is Too High, guess lower';
}
}
}
function restart() {
luckyNumber = Math.floor(Math.random()*20);
console.log(luckyNumber);
score = 20;
mainSection.style.backgroundColor = '#222';
marker.innerText = '?';
message.innerText = 'Start Guessing...';
}
checkbtn.addEventListener('click',checkYourGuess);
againbtn.addEventListener('click',restart);