Skip to content

day 05 changes #6

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 1 commit into from
Feb 23, 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: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ I am an independent educator and open-source enthusiast who creates meaningful p
- **`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: Mater 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: Matering 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 04: Matering 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: Matering 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)
2 changes: 1 addition & 1 deletion day-04/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ I am an independent educator and open-source enthusiast who creates meaningful p
## Video
Here is the video for you to go through and learn:

[![day-03](./banner.png)](https://youtu.be/Fn_DhBu3VyU "Video")
[![day-04](./banner.png)](https://youtu.be/Fn_DhBu3VyU "Video")

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

Expand Down
36 changes: 36 additions & 0 deletions day-05/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Day 05 - 40 Days of JavaScript

## **🎯 Goal of This Lesson**

- ✅ Logic Building and DSA
- ✅ Loops in JavaScript
- ✅ The for Loop
- ✅ The for Loop Flow Chart
- ✅ for Loop Examples
- ✅ Nested Loop
- ✅ The break and continue
- ✅ Handling Multiple Counters
- ✅ The while Loop
- ✅ The do-while Loop
- ✅ Infinite Loop
- ✅ Task and Wrap Up

## 🫶 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-05](./banner.png)](https://youtu.be/MDR43-2GvtA "Video")

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

Please find the task assignments in the [Task File](./task.md).
Binary file added day-05/banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions day-05/index.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>Day 05</title>
<script src="./index.js"></script>
</head>
<body>
<h1>Welcome to the <u>Day 05</u> of "40 Days of JavaScript!"</h1>
</body>
</html>
112 changes: 112 additions & 0 deletions day-05/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
console.log("day 05");

// for loop
// “A for loop is best when we know exactly how many times we need to run a block of code.”

/*
for (initialization; condition; update) {
// Code
}
*/

for (let count=1; count <= 5; count++ ) {
console.log("Iteration/Loop", count)
}

// Addition of even numbers between 1 to 100

let sum = 0;
for (let i = 1; i<= 100; i++) {
if (i % 2 === 0) {
//console.log("i", i)
//sum = sum + i;
sum += i;
}
}

console.log("Sum is", sum);

let language = "JavaScript";

for (let i = 0; i < language.length; i++) {
console.log(language.charAt(i))
}

// Nested Loop

for(let i =1; i<=3; i++) {
for(let j=1; j<=3; j++) {
console.log("Row", i, "Col", j)
}
}

// Break and Continue

for (let i=1; i<=5; i++) {
if (i===3) break;
console.log(i)
}

// Continue

for (let i=1; i<=5; i++) {
if (i===3) continue;
console.log(i)
}

// Multiple Counters for single loop

for(let i=1, j=10; i<=10 && j>=1 ; i++, j--) {
console.log(i, j);
}

/*
*
* *
* * *
* * * *
* * * * *
*/

// While Loop
// “A while loop runs as long as a given condition is true. It’s best when we don’t know in advance how many iterations are needed.”
/*
while(condition) {
// Code
}
*/

let counter = 1;
while(counter <=5) {
console.log(counter);
counter++;
}

// do-while
// “A do-while loop ensures that the code executes at least once before checking the condition.”
/*
do {
// Code
} while(condition);
*/

let num = 1;
do {
console.log(num);
num++;
} while(num <=5)


// Infinite Loop

for(;;){
console.log("I am looping forever!!!")
}

while(true) {

}

do {
// Code
} while(true)
42 changes: 42 additions & 0 deletions day-05/task.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# 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. Generate a Pyramid Pattern using Nested Loop as it is shown below:

```bash
*
* *
* * *
* * * *
* * * * *
```

## 2. Craete Multiplication Table (Using for loop)
Write a program to print the multiplication table of a given number up to 10.
For Example: If N = 3, output should be:

```bash
3 x 1 = 3
3 x 2 = 6
...
3 x 10 = 30
```

## 3. Find the summation of all odd numbers between 1 to 500 and print them on teh console log.

## 4. Skipping Multiples of 3
Write a program to print numbers from 1 to 20, but skip multiples of 3.

## 5. Reverse Digits of a Number (Using while loop)
Write a program to reverse the digits of a given number using a while loop.

Example:

```bash
Input: 6789
Output: 9876
```

## 6. Write your understanding on the difefrences between for, while, and do-while loop. Create their flow charts.