From 57de30307b50601b7c4bce91d483f944826d43d7 Mon Sep 17 00:00:00 2001 From: Misbah Aziz <92409310+maziz7508@users.noreply.github.com> Date: Sun, 26 Oct 2025 22:13:08 +0500 Subject: [PATCH] Add files via upload This is an app where a secret number is created at the start of the game, and you can enter any number in the guess section,it will compare the number with the actual number and return the result as greater or less if not equal, and win the game if the number is guessed. --- .prettierrc | 1 + README.md | 136 +--------------------------------------------------- index.html | 32 +++++++++++++ script.js | 110 ++++++++++++++++++++++++++++++++++++++++++ style.css | 119 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 264 insertions(+), 134 deletions(-) create mode 100644 .prettierrc create mode 100644 index.html create mode 100644 script.js create mode 100644 style.css diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000000..7f1b0c0128 --- /dev/null +++ b/.prettierrc @@ -0,0 +1 @@ +{ "sigleQuote": true, "arrowParens": "avoid" } diff --git a/README.md b/README.md index 75b9eca629..1f39e07648 100644 --- a/README.md +++ b/README.md @@ -1,134 +1,2 @@ -# 🎃 HacktoberFest Starter Project 🎃 - -** __Oct 24th, 2017 Update:__ THIS REPO IS TEMPORARILY __NOT MERGING NEW PRs__ until the CONTRIBUTORS.md file is sorted! Thanks for your patience! ** - -Use this project to make your first contribution to an open source project on GitHub. Practice making your first pull request to a public repository before doing the real thing! - -Celebrate [Hacktoberfest](https://hacktoberfest.digitalocean.com/) by getting involved in the open source community by completing some simple tasks in this project. - -This repository is open to all members of the GitHub community. Any member may contribute to this project without being a collaborator. - -[https://alicewonderland.github.io/hacktoberfest/](https://alicewonderland.github.io/hacktoberfest/) - -## What is Hacktoberfest? -A month-long celebration from October 1st - 31st sponsored by [Digital Ocean](https://hacktoberfest.digitalocean.com/) and [GitHub](https://github.com/blog/2433-celebrate-open-source-this-october-with-hacktoberfest) to get people involved in [Open Source](https://github.com/open-source). Create your very first pull request to any public repository on GitHub and contribute to the open source developer community. - -[https://hacktoberfest.digitalocean.com/](https://hacktoberfest.digitalocean.com/) - -## How to contribute to this project -Here are 3 quick and painless ways to contribute to this project: - -* Add your name to the `CONTRIBUTORS.md` file -* Add a profile page to the `profiles` directory -* Create a simple "Hello, World" script in a language of your choice - -Choose one or all 3, make a pull request for your work and wait for it to be merged! - -## Getting started -* Fork this repository (Click the Fork button in the top right of this page, click your Profile Image) -* Clone your fork down to your local machine - -```markdown -git clone https://github.com/your-username/hacktoberfest.git -``` - -* Create a branch - -```markdown -git checkout -b branch-name -``` - -* Make your changes (choose from any task below) -* Commit and push - -```markdown -git add . -git commit -m 'Commit message' -git push origin branch-name -``` - -* Create a new pull request from your forked repository (Click the `New Pull Request` button located at the top of your repo) -* Wait for your PR review and merge approval! -* __Star this repository__ if you had fun! - -## Choose from these tasks -### 1. Add your name -Add your name to the `CONTRIBUTORS.md` file using the below convention: - -```markdown -#### Name: [YOUR NAME](GitHub link) -- Place: City, State, Country -- Bio: Who are you? -- GitHub: [GitHub account name](GitHub link) -``` - -### 2. Add a profile page -Add a `Your_Name.md` file to the `profiles` directory. Use any combination of content and Markdown you'd like. Here is an example: - -```markdown -# Your Name - -### Location - -Your City/Country - -### Academics - -Your School - -### Interests - -- Some Things You Like - -### Development - -- Inventor of the My Pillow - -### Projects - -- [My Project](GitHub Link) Short Description - -### Profile Link - -[Your Name](GitHub Link) -``` - -### 3. Create a `Hello, World!` Script -Add a `hello_world_yourusername.xx` script to the `scripts` directory in any language of your choice! Here is an example: - -```Javascript -// LANGUAGE: Javascript -// ENV: Node.js -// AUTHOR: Alice Chuang -// GITHUB: https://github.com/AliceWonderland - -console.log('Hello, World!'); -``` - -Name the file `hello_world_yourusername.xx`. e.g., `hello_world_alicewonderland.js` or `hello_world_alicewonderland.py`. - -Don't forget to include the comments as seen above. Feel free to include additional information about the language you choose in your comments too! Like a link to a helpful introduction or tutorial. - -Here is my `hello_world` example: [hello_world_alicewonderland.js](https://github.com/AliceWonderland/hacktoberfest/blob/master/scripts/hello_world_alicewonderland.js) - -## BONUS! -* See profiles submitted by fellow coders from around the globe ... from Kathmandu to Copenhagen. -* Discover some obscure to new and trending languages ... from BrainFuck to Groovy. -* Check out some very creative ways to print out a "Hello, World!" string. - -## Reference links -Here is a great tutorial for creating your first pull request by [Roshan Jossey](https://github.com/Roshanjossey): -[https://github.com/Roshanjossey/first-contributions](https://github.com/Roshanjossey/first-contributions) - -Managing your Forked Repo: [https://help.github.com/articles/fork-a-repo/](https://help.github.com/articles/fork-a-repo/) - -Syncing a Fork: [https://help.github.com/articles/syncing-a-fork/](https://help.github.com/articles/syncing-a-fork/) - -Keep Your Fork Synced: [https://gist.github.com/CristinaSolana/1885435](https://gist.github.com/CristinaSolana/1885435) - -Checkout this list for README examples - Awesome README [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome) - -Github-Flavored Markdown [https://guides.github.com/features/mastering-markdown/](https://guides.github.com/features/mastering-markdown/) - -## Additional references added by contributors -GitHub license explained [https://choosealicense.com](https://choosealicense.com) +# Guess-The-Number +JavaScript based a small app for guessing a umber and scoring according tothe wrong and right guesses diff --git a/index.html b/index.html new file mode 100644 index 0000000000..e0df78350e --- /dev/null +++ b/index.html @@ -0,0 +1,32 @@ + + + + + + + + Guess My Number! + + +
+

Guess My Number!

+

(Between 1 and 20)

+ +
?
+
+
+
+ + +
+
+

Start guessing...

+

💯 Score: 20

+

+ 🥇 Highscore: 0 +

+
+
+ + + diff --git a/script.js b/script.js new file mode 100644 index 0000000000..7ce1b2ae50 --- /dev/null +++ b/script.js @@ -0,0 +1,110 @@ +"use strict"; + +/* +console.log(document.querySelector('.message').textContent); +document.querySelector('.message').textContent = '🎉 Correct Number!'; + +document.querySelector('.number').textContent = 13; +document.querySelector('.score').textContent = 10; + +document.querySelector('.guess').value = 23; +console.log(document.querySelector('.guess').value); +*/ + +let secretNumber = Math.trunc(Math.random() * 20) + 1; +console.log(secretNumber); + +let highScore = 0; +const displayMessage = function (message) { + document.querySelector(".message").textContent = message; +}; + +document.querySelector("body").style.backgroundColor = "#12566b"; +document.querySelector(".number").style.width = "30rem"; +let score = 20; +document.querySelector(".check").addEventListener("click", function () { + const guess = Number(document.querySelector(".guess").value); + console.log(guess, typeof guess); + + //when there's no input + if (!guess) { + // document.querySelector(".message").textContent = "⛔ No Number!"; + displayMessage("⛔ No Number!"); + } + //when player wins + else if (guess === secretNumber) { + // document.querySelector(".message").textContent = "🎉 Correct Number!"; + displayMessage("🎉 Correct Number!"); + document.querySelector(".number").textContent = secretNumber; + document.querySelector("body").style.backgroundColor = "#12566b"; + console.log(secretNumber); + + if (score > highScore) { + highScore = score; + document.querySelector(".highscore").textContent = highScore; + } + } else if (guess !== secretNumber) { + if (score > 1) { + // document.querySelector(".message").textContent = + // guess > secretNumber ? "📈 Too High!" : "📉 Too Low!"; + displayMessage(guess > secretNumber ? "📈 Too High!" : "📉 Too Low!"); + score--; + document.querySelector(".score").textContent = score; + } else { + // document.querySelector(".message").textContent = "💣 You lost the game!"; + displayMessage("💣 You lost the game!"); + document.querySelector(".score").textContent = 0; + } + } + + // //when guess is too high + // else if (guess > secretNumber) { + // if (score > 1) { + // document.querySelector(".message").textContent = "📈 Too High!"; + // score--; + // document.querySelector(".score").textContent = score; + // } else { + // document.querySelector(".message").textContent = "💣 You lost the game!"; + // document.querySelector(".score").textContent = 0; + // } + // } + + // //when guess is too low + // else if (guess < secretNumber) { + // if (score > 1) { + // document.querySelector(".message").textContent = "📉 Too Low!"; + // score--; + // document.querySelector(".score").textContent = score; + // } else { + // document.querySelector(".message").textContent = "💣 You lost the game!"; + // document.querySelector(".score").textContent = 0; + // } + // } +}); + +/////////////////////////////////////// +// Coding Challenge #1 + +/* +Implement a game rest functionality, so that the player can make a new guess! Here is how: + +1. Select the element with the 'again' class and attach a click event handler +2. In the handler function, restore initial values of the score and secretNumber variables +3. Restore the initial conditions of the message, number, score and guess input field +4. Also restore the original background color (#222) and number width (15rem) + +GOOD LUCK 😀 +*/ + +document.querySelector(".again").addEventListener("click", function () { + score = 20; + secretNumber = Math.trunc(Math.random() * 20) + 1; + console.log("Secret Number Again", secretNumber); + // document.querySelector(".message").textContent = "Start guessing..."; + displayMessage("Start guessing..."); + document.querySelector(".score").textContent = score; + document.querySelector(".number").textContent = "?"; + document.querySelector(".guess").value = ""; + document.querySelector("body").style.backgroundColor = "#222"; + document.querySelector(".number").style.width = "15rem"; +}); diff --git a/style.css b/style.css new file mode 100644 index 0000000000..e4056d6f73 --- /dev/null +++ b/style.css @@ -0,0 +1,119 @@ +@import url("https://fonts.googleapis.com/css?family=Press+Start+2P&display=swap"); + +* { + margin: 0; + padding: 0; + box-sizing: inherit; +} + +html { + font-size: 62.5%; + box-sizing: border-box; +} + +body { + font-family: "Press Start 2P", sans-serif; + color: #eee; + background-color: #222; + /* background-color: #12566b; */ +} + +/* LAYOUT */ +header { + position: relative; + height: 35vh; + border-bottom: 7px solid #eee; +} + +main { + height: 65vh; + color: #eee; + display: flex; + align-items: center; + justify-content: space-around; +} + +.left { + width: 52rem; + display: flex; + flex-direction: column; + align-items: center; +} + +.right { + width: 52rem; + font-size: 2rem; +} + +/* ELEMENTS STYLE */ +h1 { + font-size: 4rem; + text-align: center; + position: absolute; + width: 100%; + top: 52%; + left: 50%; + transform: translate(-50%, -50%); +} + +.number { + background: #eee; + color: #333; + font-size: 6rem; + width: 15rem; + padding: 3rem 0rem; + text-align: center; + position: absolute; + bottom: 0; + left: 50%; + transform: translate(-50%, 50%); +} + +.between { + font-size: 1.4rem; + position: absolute; + top: 2rem; + right: 2rem; +} + +.again { + position: absolute; + top: 2rem; + left: 2rem; +} + +.guess { + background: none; + border: 4px solid #eee; + font-family: inherit; + color: inherit; + font-size: 5rem; + padding: 2.5rem; + width: 25rem; + text-align: center; + display: block; + margin-bottom: 3rem; +} + +.btn { + border: none; + background-color: #eee; + color: #222; + font-size: 2rem; + font-family: inherit; + padding: 2rem 3rem; + cursor: pointer; +} + +.btn:hover { + background-color: #ccc; +} + +.message { + margin-bottom: 8rem; + height: 3rem; +} + +.label-score { + margin-bottom: 2rem; +}