From f8cd4a5ca7042639eda89e56af81e258c122400f Mon Sep 17 00:00:00 2001 From: Karan <50290386+Sonawane-Karan26@users.noreply.github.com> Date: Wed, 24 Nov 2021 20:27:27 +0530 Subject: [PATCH] Commit --- Chapter 6/Exercise 6.1.txt | 7 +++++++ Chapter 6/Exercise 6.2.txt | 8 ++++++++ Chapter 6/Exercise 6.3.txt | 11 +++++++++++ Chapter 6/Exercise 6.4.txt | 16 ++++++++++++++++ Chapter 6/Exercise 6.5.txt | 17 +++++++++++++++++ Chapter 6/Exercise 6.6.txt | 10 ++++++++++ Chapter 6/Exercise 6.7.txt | 18 ++++++++++++++++++ Chapter 6/Exercise 6.8.txt | 9 +++++++++ Chapter 6/Project 1.txt | 8 ++++++++ Chapter 6/Project 2.txt | 13 +++++++++++++ 10 files changed, 117 insertions(+) create mode 100644 Chapter 6/Exercise 6.1.txt create mode 100644 Chapter 6/Exercise 6.2.txt create mode 100644 Chapter 6/Exercise 6.3.txt create mode 100644 Chapter 6/Exercise 6.4.txt create mode 100644 Chapter 6/Exercise 6.5.txt create mode 100644 Chapter 6/Exercise 6.6.txt create mode 100644 Chapter 6/Exercise 6.7.txt create mode 100644 Chapter 6/Exercise 6.8.txt create mode 100644 Chapter 6/Project 1.txt create mode 100644 Chapter 6/Project 2.txt diff --git a/Chapter 6/Exercise 6.1.txt b/Chapter 6/Exercise 6.1.txt new file mode 100644 index 0000000..9d57ec8 --- /dev/null +++ b/Chapter 6/Exercise 6.1.txt @@ -0,0 +1,7 @@ +function adder(a, b) { +return a + b; +} +const val1 = 10; +const val2 = 20; +console.log(adder(val1, val2)); +console.log(adder(20, 30)); \ No newline at end of file diff --git a/Chapter 6/Exercise 6.2.txt b/Chapter 6/Exercise 6.2.txt new file mode 100644 index 0000000..cc01504 --- /dev/null +++ b/Chapter 6/Exercise 6.2.txt @@ -0,0 +1,8 @@ +const adj = ["super", "wonderful", "bad", "angry", "careful"]; + +function myFun() { + const question = prompt("What is your name?"); + const nameAdj = Math.floor(Math.random() * adj.length); + console.log(adj[nameAdj] + " " + question ); +} +myFun(); diff --git a/Chapter 6/Exercise 6.3.txt b/Chapter 6/Exercise 6.3.txt new file mode 100644 index 0000000..977d44c --- /dev/null +++ b/Chapter 6/Exercise 6.3.txt @@ -0,0 +1,11 @@ +const val1 = 10; +const val2 = 5; +let operat = "-"; +function cal(a, b, op) { + if (op == "-") { + console.log(a — b); + } else { + console.log(a + b); + } +} +cal(val1, val2, operat); \ No newline at end of file diff --git a/Chapter 6/Exercise 6.4.txt b/Chapter 6/Exercise 6.4.txt new file mode 100644 index 0000000..56c9cd2 --- /dev/null +++ b/Chapter 6/Exercise 6.4.txt @@ -0,0 +1,16 @@ +const myArr = []; + +for(let x=0; x<10; x++){ + let val1 = 5 * x; + let val2 = x * x; + let res = cal(val1, val2, "+"); + myArr.push(res); +} +console.log(myArr); +function cal(a, b, op) { + if (op == "-") { + return a - b; + } else { + return a + b; + } +} \ No newline at end of file diff --git a/Chapter 6/Exercise 6.5.txt b/Chapter 6/Exercise 6.5.txt new file mode 100644 index 0000000..013d083 --- /dev/null +++ b/Chapter 6/Exercise 6.5.txt @@ -0,0 +1,17 @@ +let val = "1000"; + +(function () { + let val = "100"; // local scope variable + console.log(val); +})(); + +let result = (function () { + let val = "Laurence"; + return val; +})(); +console.log(result); +console.log(val); + +(function (val) { + console.log(`My name is ${val}`); +})("Laurence"); \ No newline at end of file diff --git a/Chapter 6/Exercise 6.6.txt b/Chapter 6/Exercise 6.6.txt new file mode 100644 index 0000000..c891f33 --- /dev/null +++ b/Chapter 6/Exercise 6.6.txt @@ -0,0 +1,10 @@ +function calcFactorial(nr) { + console.log(nr); + if (nr === 0) { + return 1; + } + else { + return nr * calcFactorial(--nr); + } +} +console.log(calcFactorial(4)); diff --git a/Chapter 6/Exercise 6.7.txt b/Chapter 6/Exercise 6.7.txt new file mode 100644 index 0000000..b6247c5 --- /dev/null +++ b/Chapter 6/Exercise 6.7.txt @@ -0,0 +1,18 @@ +let start = 10; +function loop1(val) { + console.log(val); + if (val < 1) { + return + } + return loop1(val - 1); +} +loop1(start); +function loop2(val) { + console.log(val); + if (val > 0) { + val--; + return loop2(val); + } + return; +} +loop2(start); diff --git a/Chapter 6/Exercise 6.8.txt b/Chapter 6/Exercise 6.8.txt new file mode 100644 index 0000000..e1a4a19 --- /dev/null +++ b/Chapter 6/Exercise 6.8.txt @@ -0,0 +1,9 @@ +const test = function(val){ + console.log(val); +} +test('hello 1'); + +function test1(val){ + console.log(val); +} +test1("hello 2"); \ No newline at end of file diff --git a/Chapter 6/Project 1.txt b/Chapter 6/Project 1.txt new file mode 100644 index 0000000..32d3ecb --- /dev/null +++ b/Chapter 6/Project 1.txt @@ -0,0 +1,8 @@ +const main = function counter(i) { +console.log(i); +if (i < 10) { + return counter(i + 1); +} +return; +} +main(0); \ No newline at end of file diff --git a/Chapter 6/Project 2.txt b/Chapter 6/Project 2.txt new file mode 100644 index 0000000..a4186f0 --- /dev/null +++ b/Chapter 6/Project 2.txt @@ -0,0 +1,13 @@ +const one = ()=> console.log('one'); +const two = ()=> console.log('two'); +const three = () =>{ + console.log('three'); + one(); + two(); +} +const four = () =>{ + console.log('four'); + setTimeout(one,0); + three(); +} +four(); \ No newline at end of file