Skip to content

Day 07 #9

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

Merged
merged 3 commits into from
Mar 2, 2025
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ I am an independent educator and open-source enthusiast who creates meaningful p

## Table of Content

### Module 1

- **`Day 01: Introduction to JavaScript & Setting Up the Environment`** - [Watch Video](https://youtu.be/t8QXF85YovE) || [Source Code](https://github.com/tapascript/40-days-of-javascript/blob/main/day-01/README.md)
- **`Day 02: Variables (let, const, var) & Data Types`** - [Watch Video](https://www.youtube.com/watch?v=tVqy4Tw0i64) || [Source Code](https://github.com/tapascript/40-days-of-javascript/blob/main/day-02/README.md)
- **`Day 03: Master Operators and Expressions`** - [Watch Video](https://youtu.be/vI95K-_JLOw) || [Source Code](https://github.com/tapascript/40-days-of-javascript/blob/main/day-03/README.md)
- **`Day 04: Mastering Control Flow with Quizzes`** - [Watch Video](https://youtu.be/Fn_DhBu3VyU) || [Source Code](https://github.com/tapascript/40-days-of-javascript/blob/main/day-04/README.md)
- **`Day 05: Mastering Loops and Iterations with Quizzes`** - [Watch Video](https://youtu.be/MDR43-2GvtA) || [Source Code](https://github.com/tapascript/40-days-of-javascript/blob/main/day-05/README.md)
- **`Day 06: Mastering Functions and its Use Cases with Quizzes`** - [Watch Video](https://youtu.be/6UJ9SyHvkJY) || [Source Code](https://github.com/tapascript/40-days-of-javascript/blob/main/day-06/README.md)
- **`Day 07: Building Beginner-Friendly JavaScript Projects`** - [Watch Video](https://youtu.be/fydbEttef04) || [Source Code](https://github.com/tapascript/40-days-of-javascript/blob/main/day-07/README.md)
4 changes: 2 additions & 2 deletions day-06/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Day 05 - 40 Days of JavaScript
# Day 06 - 40 Days of JavaScript

## **🎯 Goal of This Lesson**

Expand Down Expand Up @@ -31,7 +31,7 @@ Your support means a lot.
### 🤝 Sponsor My Work
I am an independent educator and open-source enthusiast who creates meaningful projects to teach programming on my YouTube Channel. **You can support my work by [Sponsoring me on GitHub](https://github.com/sponsors/atapas) or [Buy Me a Cofee](https://buymeacoffee.com/tapasadhikary)**.

## Video
## Video
Here is the video for you to go through and learn:

[![day-06](./banner.png)](https://www.youtube.com/watch?v=6UJ9SyHvkJY "Video")
Expand Down
26 changes: 26 additions & 0 deletions day-07/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Day 07 - 40 Days of JavaScript

## **🎯 Goal of This Lesson**

- ✅ Build the Project
- ✅ Give an Assignment Project to Build

## 🫶 Support
Your support means a lot.

- Please SUBSCRIBE to [tapaScript YouTube Channel](https://youtube.com/tapasadhikary) if not done already. A Big Thank You!
- Liked my work? It takes months of hard work to create quality content and present it to you. You can show your support to me with a STAR(⭐) to this repository.

> Many Thanks to all the `Stargazers` who have supported this project with stars(⭐)

### 🤝 Sponsor My Work
I am an independent educator and open-source enthusiast who creates meaningful projects to teach programming on my YouTube Channel. **You can support my work by [Sponsoring me on GitHub](https://github.com/sponsors/atapas) or [Buy Me a Cofee](https://buymeacoffee.com/tapasadhikary)**.

## Video
Here is the video for you to go through and learn:

[![day-07](./banner.png)](https://youtu.be/fydbEttef04 "Video")

## **👩‍💻 🧑‍💻 Assignment Tasks**

Please find the task assignments in the [Task File](./task.md).
Binary file added day-07/banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions day-07/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Day 07</title>
</head>

<body>
<div>
<a href="./rps/rps.html">Rock Paper Scissors</a>

<a href="./secret-number/secret-number.html">Guess The Secret Number Name</a>
</div>

</body>

</html>
12 changes: 12 additions & 0 deletions day-07/rps/rps.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Rock Paper Scissors</title>
<script defer src="./rps.js"></script>
</head>
<body>
<h1>Day 07 - Rock Paper Scissors Project</h1>
</body>
</html>
66 changes: 66 additions & 0 deletions day-07/rps/rps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* The Rock 🪨, Paper 🧻, or Scissors ✂️ Game
* This game will be played between the computer and human. Once Human will select Rock, Paper, or Scissors and in the next turn the computer will select Rock, Paper, or Scissors.
* The Winner will be selected based on these rules:
* - Rock can Break Scissors => Rock Wins
* - Paper can wrap Rock => paper Wins
* - Scissors can cut Paper => Scissors Wins
* Ask the input from user and randomly select a computer selection to continue the game.
*/

// Assumptions:
// 1. We have to prompt the user to get their inputs.
// 2. The Computer's selection will be random.
// 3. We have to compare user and computer's choice
// 4. We need to announce the winner.
// 5. After the Winner announcement, we may want to ask the user to play again or quit from the game.

function rockPaperScissorsGame() {
console.log("Getting Started With the Rock 🪨, Paper 🧻, or Scissors ✂️ Game");
const userChoicePrompt = prompt("Enter Rock 🪨, Paper 🧻, or Scissors ✂️");
const userChoice = userChoicePrompt.toLowerCase();

let computerChoice;
const randomNumber = Math.floor(Math.random() * 3) + 1;

if (randomNumber === 1) {
computerChoice = "rock";
} else if (randomNumber === 2) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
}

console.log("User selected", userChoice);
console.log("Computer selected", computerChoice);

if (
(userChoice === "rock" && computerChoice === "scissors") ||
(userChoice === "paper" && computerChoice === "rock") ||
(userChoice === "scissors" && computerChoice === "paper")
) {
console.log("You the User WIN, yay!!!!");
} else if ( userChoice === computerChoice) {
console.log("The Game is a Tie");
} else if(
(userChoice === "rock" && computerChoice === "paper") ||
(userChoice === "paper" && computerChoice === "scissors") ||
(userChoice === "scissors" && computerChoice === "rock")
) {
console.log("Oh Ho... Computer Wins!!!!");
} else {
console.log("Please check the input, We didn't understand it.")
}

const playAgainPrompt = prompt("Do You Want to Play Again? (yes/no)")
const playAgain = playAgainPrompt ? playAgainPrompt.toLowerCase() : "no";

if (playAgain === "yes") {
rockPaperScissorsGame();
} else {
console.log("Thanks for Playing! See you Next Time")
}
}

// Start This Game
rockPaperScissorsGame();
12 changes: 12 additions & 0 deletions day-07/secret-number/secret-number.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Guess The Secret Number</title>
<script defer src="./secret-number.js"></script>
</head>
<body>
<h1>Day 07 - Guess The Secret Number Project</h1>
</body>
</html>
64 changes: 64 additions & 0 deletions day-07/secret-number/secret-number.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* Let us play a number guessing game.
* You will ask user for a number between 1 to 10. Once user will enter a number, you will tell user if the entered number is lower or higher. With this information, user will change the number and finally guess the right number. You also need to show the number of attempts made by users to rach to this right guess.
*/

// max number
// min number

// secret number is a random number between the min and max

// get the prommpt from the user as a guess

// Create a variable to store the number of attempts

// Write the logic to check if the guess and the secret number are same. If not continue a loop to ask again.

// Inside loop check if the guess is less than the secret or greater than, accordingly tell if the guess it low or high

// Give the option to play again

const MIN_NUMBER = 1;
const MAX_NUMBER = 10;

function startSecretNumberGame() {
const secretNumber = Math.floor(Math.random() * MAX_NUMBER) + 1;
let attempts = 0;
let guess = null;

console.log("Welcome to the Number Guessing Game!");
console.log("Try to guess a number between 1 and 10.");

while (guess !== secretNumber) {
const guessPrompt = prompt("Enter your guess: ");
guess = parseInt(guessPrompt);

if (isNaN(guess) || guess < MIN_NUMBER || guess > MAX_NUMBER) {
console.log(`Invalid input! Please enter a number between ${MIN_NUMBER} and ${MAX_NUMBER}.`);
continue;
}

attempts++;

if (guess < secretNumber) {
console.log("Too Low! Try again.");
} else if (guess > secretNumber) {
console.log("Too High! Try again.");
} else {
console.log(`🎉 Congrats! You guessed the number in ${attempts} attempts.`);
break;
}
}

const playAgainPrompt = prompt("Do you want to play again? (yes/no)");
console.log(playAgainPrompt);
const playAgain = playAgainPrompt ? playAgainPrompt.toLocaleLowerCase() : "no";
if (playAgain === "yes") {
startSecretNumberGame();
} else {
console.log("Thanks for playing! See you next time.");
}
}

// Start the game
startSecretNumberGame();
10 changes: 10 additions & 0 deletions day-07/task.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Tasks
Please complete the following tasks and post them on the tapaScript Discord under "40 Days of JavaScript".

> **DO NOT USE AI to FIND ANSWERS**. If you are stuck, let's discuss it on DISCORD and learn. Also, please note that none of the answers need you to create any UI. Just focus on the logic building and print the output on the browser console.

## 1. Change the RPS Project
Change the if-else to switch-case as asked in the video(at 15:42).

## 2. Build the Secret Number Guessing Game
Create the project as explained in the video.