Skip to content

(feat) Day 06 lesson #8

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 2 commits into from
Feb 26, 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 @@ -22,4 +22,5 @@ I am an independent educator and open-source enthusiast who creates meaningful p
- **`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 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-05/README.md)
4 changes: 2 additions & 2 deletions day-05/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 @@ -29,7 +29,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-05](./banner.png)](https://youtu.be/MDR43-2GvtA "Video")
[![day-05](./banner.png)](https://www.youtube.com/watch?v=MDR43-2GvtA&list=PLIJrr73KDmRw2Fwwjt6cPC_tk5vcSICCu&index=5 "Video")

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

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

## **🎯 Goal of This Lesson**

- ✅ What Will We Learn
- ✅ What is Function
- ✅ Define a Function
- ✅ Invoking a Function
- ✅ Function as Expression
- ✅ Parameter and Argument
- ✅ Default Parameters
- ✅ Rest parameter
- ✅ Nested Functions
- ✅ Callback Function
- ✅ Pure Function
- ✅ Higher Order Function
- ✅ Arrow Function
- ✅ IIFE
- ✅ Call Stack
- ✅ Recursion
- ✅ 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-06/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-06/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 06</title>
<script src="./index.js"></script>
</head>
<body>
<h1>Welcome to the <u>Day 06</u> of "40 Days of JavaScript!"</h1>
</body>
</html>
160 changes: 160 additions & 0 deletions day-06/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
console.log("Day 06");

// Define or Declare a Function
function printThis() {
console.log("Printing...")
}

// Call or Invoke a Function
printThis();

// Function as an Expression
let printMe = function() {
console.log("Print Me")
}

printMe();

// Parameters & Arguments
function sum(a, b) {
const result = a + b;
//console.log(result);
return result;
}

let result = sum(10, 9);
console.log(result)

function double(x) {
return 2*x;
}
console.log(double(result));

// Default Parameters

function calc(a=0, b=0) {
return (2 * (a + b ))
}

const resVar = calc()
console.log(resVar);


// Rest Parameter
function calculateThis(x, y, ...rest){
console.log(x, y, rest)
}

calculateThis(1,2,3,4,5,6,7,8,9)

// Nested Fucntion

function outer() {
console.log("Outer");

return function inner() {
console.log("inner")
}
//inner();
}

let retFunc = outer();

console.log(retFunc());


// callback function
const toCallBuz = false;

function foo(func) {
console.log("foo");
if (toCallBuz){
func();
}
}

const buz = function() {
console.log("buz")
}

foo(buz);

// Pure function
let greeetingMsg = "Hola "

function greeting(name) {
return greeetingMsg + name;
}

console.log(greeting("tapaScript"));
console.log(greeting("tapaScript"));

greeetingMsg = "Namaste "

console.log(greeting("tapaScript"));
console.log(greeting("tapaScript"));
console.log(greeting("tapaScript"));


// Higher Order Function

function getCamera(camera) {
camera();
}

getCamera(function() {
console.log("Sony")
})

function returnFunc(param) {
return function() {
if (param === 1) {
console.log("Hello")
}

}
}

const retFun = returnFunc(3);
retFun();


// Arrow Function

let greetMe = (greetingMsg) => {
//
//
return greetingMsg + " great"
}

console.log(greetMe("Hola"));


// IIFE(Immediately Invoked Function Expression)
(function(count){
console.log("IIFE", count)
})(1)


// Recursion

/*function foo() {
foo();
}*/

function fetchWater(count) {
console.log("Fetching Water...", count);
if (count === 0) {
console.log("No more water is left to fetch...");
return;
}
fetchWater(count - 1)
}

fetchWater(5)






53 changes: 53 additions & 0 deletions day-06/task.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# 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. Write a Function to Convert Celsius to Fahrenheit
Create a function celsiusToFahrenheit(celsius) that converts a temperature from Celsius to Fahrenheit.
Formula: (Celsius * 9/5) + 32 = Fahrenheit

## 2. Create a Function to Find the Maximum of Two Numbers
Write a function findMax(num1, num2) that returns the larger of the two numbers. It should work for negative numbers as well.

## 3. Function to Check if a String is a Palindrome
Create a function isPalindrome(str) that checks if a given string is a palindrome (reads the same forward and backward). You can not use any string function that we have not learned in the series so far.

## 4. Write a Function to Find Factorial of a Number
Create a function factorial(n) that returns the factorial of n.
Example 5! = 5 * 4 * 3 * 2 * 1

## 5. Write a function to Count Vowels in a String
Write a function countVowels(str) that counts the number of vowels (a, e, i, o, u) in a given string.

## 6. Write a Function to Capitalize the First Letter of Each Word in a Sentence
Write a function capitalizeWords(sentence) that takes a sentence and capitalizes the first letter of each word. You can use the toUpperCase() method of string to convert the lowercase to uppercase.

## 7. Use an IIFE to Print “Hello, JavaScript!”
Write an IIFE that prints "Hello, JavaScript!" to the console. Here the Second word must be supplied using paramneter and argument.

## 8. Create a Simple Callback Function
Write a function greet(name, callback), where callback prints a message using the name parameter.

## 9. Create Call Stack Execution Diagram for this flow

```js
function f1() {}
function f2() {
f1();
}
f2();
```

## 10. Create Call Stack Execution Diagram for this flow

```js
function f1() {}
function f2() {}
function f3() {
f1();
}
f2();
f3();
f1();
```