Skip to content

Commit cdc934d

Browse files
committed
Code 2 - Class 14 / 3
1 parent bea609d commit cdc934d

3 files changed

Lines changed: 75 additions & 0 deletions

File tree

Block Chain Collage Code 2/14/3/css/style.css

Whitespace-only changes.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<link rel="stylesheet" href="css/style.css">
7+
<title>Guess The number</title>
8+
</head>
9+
<body>
10+
11+
<h1>Guess The number!!</h1>
12+
13+
<input type="text" id="guess">
14+
<button id="submit">Submit</button>
15+
<button id="reset">Reset the game</button>
16+
<h2 id="chance"></h2>
17+
<p id="hint"></p>
18+
<p id="showLastNumber"></p>
19+
20+
<script src="js/script.js"></script>
21+
</body>
22+
</html>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
"use strict"
2+
3+
const guessInp = document.querySelector("#guess")
4+
const submitBtn = document.querySelector("#submit")
5+
const resetBtn = document.querySelector("#reset")
6+
const chanceEl = document.querySelector("#chance")
7+
const hintEl = document.querySelector("#hint")
8+
const lastGuessEl = document.querySelector("#showLastNumber")
9+
10+
11+
let chance = 5;
12+
let randomNum = Math.trunc(Math.random() * 20 + 1)
13+
14+
chanceEl.textContent = `chance: ${chance}`;
15+
16+
submitBtn.addEventListener("click", () => {
17+
18+
chance--;
19+
chanceEl.textContent = `chance: ${chance}`
20+
const value = guessInp.value
21+
guessInp.value = ""
22+
lastGuessEl.textContent += ` ${value},`
23+
24+
if (randomNum == value) {
25+
guessInp.disable = true
26+
submitBtn.disable = true
27+
hintEl.textContent = "You Winnnnnnn!🎉"
28+
} else {
29+
if (chance > 0) {
30+
if (randomNum > value) {
31+
hintEl.textContent = "Your Guess is lower than random number";
32+
} else {
33+
hintEl.textContent = "Your Guess is higher than random number";
34+
}
35+
} else {
36+
guessInp.disable = true
37+
submitBtn.disable = true
38+
hintEl.textContent = `you lose, random number was : ${randomNum} 😂🗿`
39+
}
40+
}
41+
})
42+
43+
44+
resetBtn.addEventListener("click", () => {
45+
guessInp.disable = false
46+
submitBtn.disable = false
47+
chance = 5
48+
chanceEl.textContent = `chance: ${chance}`
49+
hintEl.textContent=""
50+
lastGuessEl.textContent=""
51+
randomNum = Math.trunc(Math.random() * 20 + 1)
52+
})
53+

0 commit comments

Comments
 (0)