-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
104 lines (90 loc) · 3.16 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
document.title = "Number guessing Game";
const trailsRemaining = document.querySelector(".trails-remain");
const winnerPage = (document.getElementsByClassName("winner"))[0].style;
const loserPage = document.getElementsByClassName("winner")[1].style;
const loserText = document.getElementById("loser-text");
const inputNumber = document.getElementById("user-input");
alert("Welcome user Guess number between 0 to 50 or you can change difficulty below");
// winnerPage.display="block";
let tasks = 5;
presetlevel = 1;
trailsRemaining.innerHTML = `Tasks remaining ${tasks}`
let randomnumber = Math.floor((Math.random() * 50) + 1);
console.log(randomnumber);
function takeInput() {
// if (inputNumber.value==null) {
// alert("Input can't be blank");
// return;
// }
if (tasks > 1) {
if (inputNumber.value == randomnumber) {
tasks = tasks - 1;
winnerPage.display = "flex";
setTimeout(() => {
winnerPage.display = "none";
inputNumber.value = null;
difficulty(presetlevel);
return;
}, 3000);
}
else{
inputNumber.value = null;
tasks = tasks - 1;
trailsRemaining.innerHTML = `Tasks remaining ${tasks}`
}
if (tasks==2&&inputNumber.value != randomnumber) {
const msgevenodd=`number is between ${randomnumber-5} and ${randomnumber+10}`;
alert(msgevenodd);
}
else if (tasks==3&&inputNumber.value != randomnumber) {
const msgevenodd=randomnumber%2==0?"number is even":"number is odd";
alert(msgevenodd);
}
}
else {
inputNumber.value = null;
tasks = tasks - 1;
loserText.innerHTML = `Oops! You Failed Text was -> ${randomnumber}`;
loserPage.display = "flex";
setTimeout(() => {
loserPage.display = "none";
trailsRemaining.innerHTML = `Tasks remaining ${tasks}`
tasks = 5;
difficulty(parseInt(presetlevel));
}, 3000);
}
}
//change difficulty
function difficulty(level) {
if (level === 1) {
inputNumber.value = null;
randomnumber = Math.floor((Math.random() * 50) + 1);
presetlevel = level;
tasks = 5;
trailsRemaining.innerHTML = `Tasks remaining ${tasks}`
console.log(randomnumber);
alert("Guess number between 0 to 50");
}
else if (level === 2) {
inputNumber.value = null;
randomnumber = Math.floor((Math.random() * 100) + 1);
tasks = 5;
presetlevel = level;
console.log(randomnumber);
trailsRemaining.innerHTML = `Tasks remaining ${tasks}`
alert("Guess number between 0 to 100");
}
else if (level === 3) {
inputNumber.value = null;
randomnumber = Math.floor((Math.random() * 1000) + 1);
tasks = 5;
console.log(randomnumber);
presetlevel = level;
trailsRemaining.innerHTML = `Tasks remaining ${tasks}`
alert("Guess number between 0 to 1000");
}
else {
console.log(level);
alert("prompt error")
}
}