From 9e5b119bdfdf22c459686d0d826eea8654e2036f Mon Sep 17 00:00:00 2001 From: Karan <50290386+Sonawane-Karan26@users.noreply.github.com> Date: Wed, 24 Nov 2021 19:36:19 +0530 Subject: [PATCH 1/9] Exercise 5.1 --- Chapter 5/Exercise 5.1 | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Chapter 5/Exercise 5.1 diff --git a/Chapter 5/Exercise 5.1 b/Chapter 5/Exercise 5.1 new file mode 100644 index 0000000..db89ec2 --- /dev/null +++ b/Chapter 5/Exercise 5.1 @@ -0,0 +1,16 @@ +const max = 5; +const ranNumber = Math.floor(Math.random() * max) + 1; +//console.log(ranNumber); +let correct = false; +while (!correct) { + let guess = prompt("Guess a Number 1 - " + max); + guess = Number(guess); + if (guess === ranNumber) { + correct = true; + console.log("You got it " + ranNumber) + } else if (guess > ranNumber) { + console.log("Too high"); + } else { + console.log("Too Low"); + } +} From 7b6bbe367a7d20fa6a504a8d37d7119a29976f9a Mon Sep 17 00:00:00 2001 From: Karan <50290386+Sonawane-Karan26@users.noreply.github.com> Date: Wed, 24 Nov 2021 19:36:45 +0530 Subject: [PATCH 2/9] Exercise 5.2 --- Chapter 5/Exercise 5.2 | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Chapter 5/Exercise 5.2 diff --git a/Chapter 5/Exercise 5.2 b/Chapter 5/Exercise 5.2 new file mode 100644 index 0000000..6669612 --- /dev/null +++ b/Chapter 5/Exercise 5.2 @@ -0,0 +1,7 @@ +let counter = 0; +let step = 5; +do { + console.log(counter); + counter += step; +} +while (counter <= 100); From 1f6a577766b48546080ec3b8791a5fffc00c7a0a Mon Sep 17 00:00:00 2001 From: Karan <50290386+Sonawane-Karan26@users.noreply.github.com> Date: Wed, 24 Nov 2021 19:37:14 +0530 Subject: [PATCH 3/9] Exercise 5.3 --- Chapter 5/Exercise 5.3 | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Chapter 5/Exercise 5.3 diff --git a/Chapter 5/Exercise 5.3 b/Chapter 5/Exercise 5.3 new file mode 100644 index 0000000..0d654f5 --- /dev/null +++ b/Chapter 5/Exercise 5.3 @@ -0,0 +1,9 @@ +const myWork = []; +for (let x = 1; x < 10; x++) { + let stat = x % 2 ? true : false; + let temp = { + name: `Lesson ${x}`, status: stat + }; + myWork.push(temp); +} +console.log(myWork); From a0f8c65fd92d63d5f1e075d3f0372b5e97771bfe Mon Sep 17 00:00:00 2001 From: Karan <50290386+Sonawane-Karan26@users.noreply.github.com> Date: Wed, 24 Nov 2021 19:37:48 +0530 Subject: [PATCH 4/9] Exercise 5.4 --- Chapter 5/Exercise 5.4 | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Chapter 5/Exercise 5.4 diff --git a/Chapter 5/Exercise 5.4 b/Chapter 5/Exercise 5.4 new file mode 100644 index 0000000..766ec7e --- /dev/null +++ b/Chapter 5/Exercise 5.4 @@ -0,0 +1,13 @@ +const myTable = []; +const rows = 4; +const cols = 7; +let counter = 0; +for (let y = 0; y < rows; y++) { + let tempTable = []; + for (let x = 0; x < cols; x++) { + counter++; + tempTable.push(counter); + } + myTable.push(tempTable); +} +console.table(myTable); From 2d93730c0b28788fdbc70d39ebafb6c4c5459446 Mon Sep 17 00:00:00 2001 From: Karan <50290386+Sonawane-Karan26@users.noreply.github.com> Date: Wed, 24 Nov 2021 19:38:41 +0530 Subject: [PATCH 5/9] Exercise 5.5 --- Chapter 5/Exercise 5.5 | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Chapter 5/Exercise 5.5 diff --git a/Chapter 5/Exercise 5.5 b/Chapter 5/Exercise 5.5 new file mode 100644 index 0000000..0e46e7d --- /dev/null +++ b/Chapter 5/Exercise 5.5 @@ -0,0 +1,17 @@ +const grid = []; +const cells = 64; +let counter = 0; +let row; +for (let x = 0; x < cells + 1; x++) { + if (counter % 8 == 0) { + if (row != undefined) { + grid.push(row); + } + row = []; + } + counter++; + let temp = counter; + row.push(temp); + +} +console.table(grid); From 3be07738886018b241d039d6b26e5e30af04535a Mon Sep 17 00:00:00 2001 From: Karan <50290386+Sonawane-Karan26@users.noreply.github.com> Date: Wed, 24 Nov 2021 19:39:19 +0530 Subject: [PATCH 6/9] Exercise 5.6 --- Chapter 5/Exercise 5.6 | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Chapter 5/Exercise 5.6 diff --git a/Chapter 5/Exercise 5.6 b/Chapter 5/Exercise 5.6 new file mode 100644 index 0000000..9d23cec --- /dev/null +++ b/Chapter 5/Exercise 5.6 @@ -0,0 +1,12 @@ +const myArray = []; +for (let x = 0; x < 10; x++) { + myArray.push(x + 1); +} +console.log(myArray); + +for (let i = 0; i < myArray.length; i++) { + console.log(myArray[i]); +} +for (let val of myArray) { + console.log(val); +} From 8692cecb8ce034d8029bef845c65ad8b35822c74 Mon Sep 17 00:00:00 2001 From: Karan <50290386+Sonawane-Karan26@users.noreply.github.com> Date: Wed, 24 Nov 2021 19:39:54 +0530 Subject: [PATCH 7/9] Exercise 5.7 --- Chapter 5/Exercise 5.7 | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Chapter 5/Exercise 5.7 diff --git a/Chapter 5/Exercise 5.7 b/Chapter 5/Exercise 5.7 new file mode 100644 index 0000000..4d306ce --- /dev/null +++ b/Chapter 5/Exercise 5.7 @@ -0,0 +1,16 @@ +const obj = { + a: 1, + b: 2, + c: 3 +}; +for (let prop in obj) { + console.log(prop, obj[prop]); +} +const arr = ["a", "b", "c"]; +for (let w = 0; w < arr.length; w++) { + console.log(w, arr[w]); +} + +for (el in arr) { + console.log(el, arr[el]); +} From edb9a9005a074c669abd01e96d87a799c14e2981 Mon Sep 17 00:00:00 2001 From: Karan <50290386+Sonawane-Karan26@users.noreply.github.com> Date: Wed, 24 Nov 2021 19:40:50 +0530 Subject: [PATCH 8/9] Exercise 5.8 --- Chapter 5/Exercise 5.8 | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Chapter 5/Exercise 5.8 diff --git a/Chapter 5/Exercise 5.8 b/Chapter 5/Exercise 5.8 new file mode 100644 index 0000000..977780b --- /dev/null +++ b/Chapter 5/Exercise 5.8 @@ -0,0 +1,23 @@ +let output = ""; +let skipThis = 7; +for (let i = 0; i < 10; i++) { + if (i === skipThis) { + continue; + } + output += i; +} +console.log(output); + + +//Alternatively, the following code could be used, replacing continue with break: + +let output = ""; +let skipThis = 7; +for (let i = 0; i < 10; i++) { + if (i === skipThis) { + break; + } + output += i; +} + +console.log(output); From b03e47b68e0fda9cc9ed5d2f9a306bb6e816d402 Mon Sep 17 00:00:00 2001 From: Karan <50290386+Sonawane-Karan26@users.noreply.github.com> Date: Wed, 24 Nov 2021 19:41:38 +0530 Subject: [PATCH 9/9] Project 1 --- Chapter 5/Project 1 | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Chapter 5/Project 1 diff --git a/Chapter 5/Project 1 b/Chapter 5/Project 1 new file mode 100644 index 0000000..8c2cba3 --- /dev/null +++ b/Chapter 5/Project 1 @@ -0,0 +1,11 @@ +const myTable = []; +const numm = 10; +for(let x=0; x