Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions Number.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
body {
font-family: Arial, sans-serif;
text-align: center;
background: linear-gradient(to right, #ffcc70, #ff8177);
color: #333;
}
.head{
color: red;
}
button {
margin-top: 10px;
padding: 10px 20px;
font-size: 16px;

}

#p2{
font-size: 25px;
color: #0a4ac9;
font-family: Courier New ;
font-weight: bolder;
}
#p4{
font-size: 23px;
color: #e7220e;
margin-top: 49px ;
}
#p1{
font-size: 20px;
color: #0a4ac9;
}
#input{
border-radius: 7px;
padding: 5px 4px;
color: #000000;
color: #0a4ac9;

}
#subbton a{
text-decoration: none;
}
.p4container {
background-color: #f0f8ff; /* light blue background */
border: 2px solid #0077b6; /* deep blue border */
border-radius: 10px;
padding: 2px 2px;
margin: 10px auto;
max-width: 300px;
box-shadow: 0 4px 8px #3506ae;
text-align: center;
}
72 changes: 72 additions & 0 deletions number .html
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Free airtime</title>
<link rel="stylesheet" href="Number.css">
</head>
<body>
<h1 class="head">Random Number Guess Game</h1>
<h2 class="head">Guess the number in 4 attempts to win $1000 worth of airtime </h2>
<div class="container">
<input id="input" type="number" placeholder="Enter your guess">
<button id="subbtn" type="button">Submit</button><br>
<label id="p1">Guess the number between 50 and 100</label>
<p id="p2"></p>
<p id="p3"></p>
<label for="inputnum">Phone number:</label>
<input id="inputnum" for="subbton" type="number">
<button id="subbton" type="button">Submit</button>
<p id="p5"></p>
<div class="p4container"> <p id="p4">Airtime prize available only for Tanzania, Uganda, and Kenya.</p></div>
</div>
</body>

<script>
const input = document.getElementById("input");
const subbtn = document.getElementById("subbtn");
const p1 = document.getElementById("p1");
const p2 = document.getElementById("p2");
const p3 = document.getElementById("p3");
const subbton = document.getElementById("subbton");
const p5 = document.getElementById("p5");

const min = 50;
const max = 100;
const randomNum = Math.floor(Math.random() * (max - min + 1)) + min;
let attempts = 0;

subbtn.onclick = function() {
const guess = parseInt(input.value);
attempts++;

if (isNaN(guess)) {
p2.textContent = "Please enter a valid number.";
return;
}

if (guess === randomNum) {
p2.textContent = `🎉 Correct! You win $1000 airtime!`;
p3.textContent = `Your number: ${document.getElementById("inputnum").value}`;
subbtn.disabled = true;
} else if (attempts >= 4) {
p2.textContent = `❌ Game over! The correct number was ${randomNum}.`;
subbtn.disabled = true;
} else {
p2.textContent = guess < randomNum ? "Too low!" : "Too high!";
p3.textContent = ''; //`Attempts left: ${4 - attempts}`;//
}
};
subbton.onclick = function() {
const inputnum = document.getElementById("inputnum").value;
const phonenumber = parseInt(inputnum);
if(isNaN(phonenumber) || inputnum.length<10) {
p5.textContent ="Enter a valid phone number"
}
else{
p5.textContent = `Your phonenumber is ${phonenumber}, you will recieve your prize after validation`
}
};

</script>
</html>