Skip to content

Commit 013d9a4

Browse files
committed
(feat) Day 06 lesson
1 parent 140edf0 commit 013d9a4

File tree

6 files changed

+270
-3
lines changed

6 files changed

+270
-3
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ I am an independent educator and open-source enthusiast who creates meaningful p
2222
- **`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)
2323
- **`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)
2424
- **`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)
25-
- **`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)
25+
- **`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)
26+
- **`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)

day-05/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Day 05 - 40 Days of JavaScript
1+
# Day 06 - 40 Days of JavaScript
22

33
## **🎯 Goal of This Lesson**
44

@@ -29,7 +29,7 @@ I am an independent educator and open-source enthusiast who creates meaningful p
2929
## Video
3030
Here is the video for you to go through and learn:
3131

32-
[![day-05](./banner.png)](https://youtu.be/MDR43-2GvtA "Video")
32+
[![day-05](./banner.png)](https://youtu.be/6UJ9SyHvkJY "Video")
3333

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

day-06/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Day 05 - 40 Days of JavaScript
2+
3+
## **🎯 Goal of This Lesson**
4+
5+
- ✅ Why to Learn
6+
- ✅ What is Function
7+
- ✅ Define a Function
8+
- ✅ Invoking a Function
9+
- ✅ Function as Expression
10+
- ✅ Parameter and Argument
11+
- ✅ Default Parameters
12+
- ✅ Rest parameter
13+
- ✅ Nested Functions
14+
- ✅ Callback Function
15+
- ✅ Pure Function
16+
- ✅ Higher Order Function
17+
- ✅ Arrow Function
18+
- ✅ IIFE
19+
- ✅ Call Stack
20+
- ✅ Recursion
21+
- ✅ Task and Wrap Up
22+
23+
## 🫶 Support
24+
Your support means a lot.
25+
26+
- Please SUBSCRIBE to [tapaScript YouTube Channel](https://youtube.com/tapasadhikary) if not done already. A Big Thank You!
27+
- 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.
28+
29+
> Many Thanks to all the `Stargazers` who have supported this project with stars(⭐)
30+
31+
### 🤝 Sponsor My Work
32+
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)**.
33+
34+
## Video
35+
Here is the video for you to go through and learn:
36+
37+
[![day-05](./banner.png)](https://youtu.be/MDR43-2GvtA "Video")
38+
39+
## **👩‍💻 🧑‍💻 Assignment Tasks**
40+
41+
Please find the task assignments in the [Task File](./task.md).

day-06/index.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Day 06</title>
7+
<script src="./index.js"></script>
8+
</head>
9+
<body>
10+
<h1>Welcome to the <u>Day 06</u> of "40 Days of JavaScript!"</h1>
11+
</body>
12+
</html>

day-06/index.js

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
console.log("Day 06");
2+
3+
// Define or Declare a Function
4+
function printThis() {
5+
console.log("Printing...")
6+
}
7+
8+
// Call or Invoke a Function
9+
printThis();
10+
11+
// Function as an Expression
12+
let printMe = function() {
13+
console.log("Print Me")
14+
}
15+
16+
printMe();
17+
18+
// Parameters & Arguments
19+
function sum(a, b) {
20+
const result = a + b;
21+
//console.log(result);
22+
return result;
23+
}
24+
25+
let result = sum(10, 9);
26+
console.log(result)
27+
28+
function double(x) {
29+
return 2*x;
30+
}
31+
console.log(double(result));
32+
33+
// Default Parameters
34+
35+
function calc(a=0, b=0) {
36+
return (2 * (a + b ))
37+
}
38+
39+
const resVar = calc()
40+
console.log(resVar);
41+
42+
43+
// Rest Parameter
44+
function calculateThis(x, y, ...rest){
45+
console.log(x, y, rest)
46+
}
47+
48+
calculateThis(1,2,3,4,5,6,7,8,9)
49+
50+
// Nested Fucntion
51+
52+
function outer() {
53+
console.log("Outer");
54+
55+
return function inner() {
56+
console.log("inner")
57+
}
58+
//inner();
59+
}
60+
61+
let retFunc = outer();
62+
63+
console.log(retFunc());
64+
65+
66+
// callback function
67+
const toCallBuz = false;
68+
69+
function foo(func) {
70+
console.log("foo");
71+
if (toCallBuz){
72+
func();
73+
}
74+
}
75+
76+
const buz = function() {
77+
console.log("buz")
78+
}
79+
80+
foo(buz);
81+
82+
// Pure function
83+
let greeetingMsg = "Hola "
84+
85+
function greeting(name) {
86+
return greeetingMsg + name;
87+
}
88+
89+
console.log(greeting("tapaScript"));
90+
console.log(greeting("tapaScript"));
91+
92+
greeetingMsg = "Namaste "
93+
94+
console.log(greeting("tapaScript"));
95+
console.log(greeting("tapaScript"));
96+
console.log(greeting("tapaScript"));
97+
98+
99+
// Higher Order Function
100+
101+
function getCamera(camera) {
102+
camera();
103+
}
104+
105+
getCamera(function() {
106+
console.log("Sony")
107+
})
108+
109+
function returnFunc(param) {
110+
return function() {
111+
if (param === 1) {
112+
console.log("Hello")
113+
}
114+
115+
}
116+
}
117+
118+
const retFun = returnFunc(3);
119+
retFun();
120+
121+
122+
// Arrow Function
123+
124+
let greetMe = (greetingMsg) => {
125+
//
126+
//
127+
return greetingMsg + " great"
128+
}
129+
130+
console.log(greetMe("Hola"));
131+
132+
133+
// IIFE(Immediately Invoked Function Expression)
134+
(function(count){
135+
console.log("IIFE", count)
136+
})(1)
137+
138+
139+
// Recursion
140+
141+
/*function foo() {
142+
foo();
143+
}*/
144+
145+
function fetchWater(count) {
146+
console.log("Fetching Water...", count);
147+
if (count === 0) {
148+
console.log("No more water is left to fetch...");
149+
return;
150+
}
151+
fetchWater(count - 1)
152+
}
153+
154+
fetchWater(5)
155+
156+
157+
158+
159+
160+

day-06/task.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Tasks
2+
Please complete the following tasks and post them on the tapaScript Discord under "40 Days of JavaScript".
3+
4+
> **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.
5+
6+
## 1. Write a Function to Convert Celsius to Fahrenheit
7+
Create a function celsiusToFahrenheit(celsius) that converts a temperature from Celsius to Fahrenheit.
8+
Formula: (Celsius * 9/5) + 32 = Fahrenheit
9+
10+
## 2. Create a Function to Find the Maximum of Two Numbers
11+
Write a function findMax(num1, num2) that returns the larger of the two numbers. It should work for negative numbers as well.
12+
13+
## 3. Function to Check if a String is a Palindrome
14+
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.
15+
16+
## 4. Write a Function to Find Factorial of a Number
17+
Create a function factorial(n) that returns the factorial of n.
18+
Example 5! = 5 * 4 * 3 * 2 * 1
19+
20+
## 5. Write a function to Count Vowels in a String
21+
Write a function countVowels(str) that counts the number of vowels (a, e, i, o, u) in a given string.
22+
23+
## 6. Write a Function to Capitalize the First Letter of Each Word in a Sentence
24+
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.
25+
26+
## 7. Use an IIFE to Print “Hello, JavaScript!”
27+
Write an IIFE that prints "Hello, JavaScript!" to the console. Here the Second word must be supplied using paramneter and argument.
28+
29+
## 8. Create a Simple Callback Function
30+
Write a function greet(name, callback), where callback prints a message using the name parameter.
31+
32+
## 9. Create Call Stack Execution Diagram for this flow
33+
34+
```js
35+
function f1() {}
36+
function f2() {
37+
f1();
38+
}
39+
f2();
40+
```
41+
42+
## 10. Create Call Stack Execution Diagram for this flow
43+
44+
```js
45+
function f1() {}
46+
function f2() {}
47+
function f3() {
48+
f1();
49+
}
50+
f2();
51+
f3();
52+
f1();
53+
```

0 commit comments

Comments
 (0)