-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
137 lines (104 loc) · 4.34 KB
/
index.html
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="//cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script src="sweetalert2.all.min.js"></script>
<link rel="shortcut icon" href="#">
<title>Guess The Number</title>
<style>
.h1{
text-align: center;
font-family: Georgia, 'Times New Roman', Times, serif;
color: rgb(17, 199, 199);
background-color: azure;
margin: 20px ;
padding: 15px;
border-radius: 10px;
list-style: none;
display: flex;
justify-content: center;
}
.innerh1{
color: lightgreen;
margin-left: 10px;
}
</style>
</head>
<body id="parent">
<ul class="h1">
<li>Guess The Number</li>
<li class="innerh1">Game</li>
</ul>
<div id="Startbtn" class="d-grid gap-2 col-3 my-5 mx-auto">
<button class="btn btn-outline-info" type="button"> Start </button>
</div>
</body>
<script>
let startButton = document.getElementById('Startbtn')
let flag = 0;
let displayDiv = document.createElement('div')
let div = document.createElement('div')
div.className = 'input-group mt-5 mx-auto w-50 text-center'
let inputGuese = document.createElement('input')
let buttonEnter = document.createElement('button')
inputGuese.className = 'form-control mb-5'
buttonEnter.className = 'btn btn-outline-success mb-5'
buttonEnter.textContent = 'Enter'
let randomNumber = Math.floor((Math.random() * 100) + 1);
let body = document.getElementById('parent').children
startButton.addEventListener('click' , start)
function start(e){
startButton.remove()
document.body.appendChild(displayDiv)
displayDiv.appendChild(div)
div.appendChild(inputGuese)
div.appendChild(buttonEnter)
}
console.log(randomNumber)
let mainDiv = document.createElement('div')
buttonEnter.addEventListener('click' , function () {
let guese = inputGuese.value ;
document.body.appendChild(mainDiv)
mainDiv.classList.add("main");
let numberOftries = mainDiv.childElementCount
if (guese == randomNumber) {
let x = numberOftries;
let textDiv = document.createElement('div')
textDiv.className = 'text.info text-center mt-3'
mainDiv.appendChild(textDiv)
textDiv.innerHTML = `This Guese is Absolutely Correct. The Number was ${randomNumber}`
Swal.fire({
title: `Congratulations. You Took ${x + 1} tries`,
text: `This Guese is Absolutely Correct. The Number was ${randomNumber}`,
icon: 'success',
confirmButtonText: 'Play Again'
}).then(function (result) {
if (result.value) {
randomNumber = Math.floor((Math.random() * 100) + 1);
console.log(randomNumber)
mainDiv.innerHTML="";
flag = 0;
}
})
}
else if (guese > randomNumber) {
let textDiv2 = document.createElement('div')
textDiv2.className = 'text.info text-center mt-3'
mainDiv.appendChild(textDiv2)
textDiv2.innerHTML = `OOPS! This Number is Larger than the Real Number`
flag = flag + 1;
}
else {
let textDiv3 = document.createElement('div')
textDiv3.className = 'text.info text-center mt-3'
mainDiv.appendChild(textDiv3)
textDiv3.innerHTML = ` OOPS! This Number is Smaller than the Real Number`
flag = flag + 1;
}
}
)
</script>
</html>