Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a Guessing number Game #853

Merged
merged 2 commits into from
Jul 24, 2023
Merged
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,4 @@ git push -u origin <your_branch_name>
<a href="https://gssoc.girlscript.tech/"><img src="https://repository-images.githubusercontent.com/331823142/9764a900-5c8e-11eb-9f94-da2a01385e83" width="10%"/></a>
</div>
<h2 align="center">Happy Contributing!🎉</h2>
<h2 align="center">Thank you</h2>
29 changes: 29 additions & 0 deletions src/Games/guessing number/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Why you want use guessing number gmae?
1.Guess the Number Game
A simple web-based "Guess the Number" game where players have to guess a randomly generated number between 1 and 100.

2.How to Play
Open the game in your web browser.
The game will prompt you to enter a number between 1 and 100 in the input field provided.
After entering your guess, click the "Submit" button to check your guess.
The game will provide feedback on whether your guess is higher or lower than the target number.
Keep guessing until you correctly guess the target number.
The game will display a congratulatory message along with the number of attempts it took to guess the correct number.
3.Technologies Used
HTML
CSS
JavaScript
Getting Started
To play the game, simply open the "index.html" file in your web browser.

bash
Copy code
git clone https://github.com/MohanaSrinivas/guess-the-number-game.git
cd guess-the-number-game
Screenshots
(Optional) Add some screenshots of the game to showcase its appearance.

4.Acknowledgments
This game was created as part of a web development practice project.
Inspired by various "Guess the Number" game tutorials and projects online.
Feel free to customize this README.md file to suit your specific project and add any additional information you think might be helpful for users or contributors. Good luck with your "Guess the Number Game" project!
20 changes: 20 additions & 0 deletions src/Games/guessing number/guess.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Guess the Number Game</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<h1>Guess the Number Game</h1>
<p>Guess a number between 1 and 100:</p>
<input type="number" id="guessInput" min="1" max="100">
<button onclick="checkGuess()">Submit</button>
<p id="message"></p>
</div>

<script src="script.js"></script>
</body>
</html>
23 changes: 23 additions & 0 deletions src/Games/guessing number/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const targetNumber = Math.floor(Math.random() * 100) + 1;
let attempts = 0;

function checkGuess() {
const guessedNumber = parseInt(document.getElementById('guessInput').value);

if (isNaN(guessedNumber) || guessedNumber < 1 || guessedNumber > 100) {
setMessage("Please enter a valid number between 1 and 100.");
} else {
attempts++;
if (guessedNumber === targetNumber) {
setMessage(`Congratulations! You guessed the correct number ${targetNumber} in ${attempts} attempts.`);
} else if (guessedNumber < targetNumber) {
setMessage("Try again! The number is higher.");
} else {
setMessage("Try again! The number is lower.");
}
}
}

function setMessage(message) {
document.getElementById('message').textContent = message;
}
36 changes: 36 additions & 0 deletions src/Games/guessing number/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
body {
font-family: Arial, sans-serif;
background-color: #f2f2f2;
}

.container {
text-align: center;
margin-top: 100px;
}

h1 {
color: #333;
}

button {
padding: 10px 20px;
background-color: #007bff;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
}

button:hover {
background-color: #0056b3;
}

input[type="number"] {
width: 50px;
padding: 5px;
}

#message {
font-size: 18px;
margin-top: 20px;
}
Loading