diff --git a/week-6/EJS-Exercises/reversing-array/index.html b/week-6/EJS-Exercises/reversing-array/index.html new file mode 100644 index 0000000..f91cc67 --- /dev/null +++ b/week-6/EJS-Exercises/reversing-array/index.html @@ -0,0 +1,15 @@ + + + + + + + Reversing an Array + + +

Hello Press F12 For Solution

+ + + + + \ No newline at end of file diff --git a/week-6/EJS-Exercises/reversing-array/main.js b/week-6/EJS-Exercises/reversing-array/main.js new file mode 100644 index 0000000..5d99193 --- /dev/null +++ b/week-6/EJS-Exercises/reversing-array/main.js @@ -0,0 +1,26 @@ +function reverseArray(array) { + empty = []; + for(let rev of array) { + empty.unshift(rev); + } + return empty; +} + +function reverseArrayInPlace(array){ + for (i = 0; i < Math.floor(array.length / 2); i++){ + // loops the array from 0 to the half of the array (rounded to lower number), increases i by one each time. + var old = array[i]; + //temporarely stores the current value of the array at the position i in the variable old. + array[i] = array[array.length - 1 - i]; + //sets the value of the i position to the value of the last element of the array minus the current i. + array[array.length - 1 - i] = old; + //sets the value of the last element of the array minus the current i to the previous value (stored in the old variable). + } +} + +console.log(reverseArray(["A", "B", "C"])); +// → ["C", "B", "A"]; +let arrayValue = [1, 2, 3, 4, 5]; +reverseArrayInPlace(arrayValue); +console.log(arrayValue); +// → [5, 4, 3, 2, 1] \ No newline at end of file diff --git a/week-6/EJS-Exercises/sum-of-range/index.html b/week-6/EJS-Exercises/sum-of-range/index.html new file mode 100644 index 0000000..ad5b706 --- /dev/null +++ b/week-6/EJS-Exercises/sum-of-range/index.html @@ -0,0 +1,15 @@ + + + + + + + Sum of Range + + +

Hello Press F12 For Solution

+ + + + + \ No newline at end of file diff --git a/week-6/EJS-Exercises/sum-of-range/main.js b/week-6/EJS-Exercises/sum-of-range/main.js new file mode 100644 index 0000000..53d1d85 --- /dev/null +++ b/week-6/EJS-Exercises/sum-of-range/main.js @@ -0,0 +1,33 @@ +function range(start,end,step){ + let array = []; + if (step == null){ + step = 1; + } + + if (start < end){ + for(i = start; i <= end; i += step){ + array.push(i); + } + } else { + for(k = start; k>= end; k += step){ + array.push(k); + } + } + return array; +} + +function sum(y) { + total = 0; + for(let x of y){ + total += x; + } + return total; +} + + +console.log(range(1, 10)); +// → [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] +console.log(range(5, 2, -1)); +// → [5, 4, 3, 2] +console.log(sum(range(1, 10))); +// → 55 \ No newline at end of file diff --git a/week-6/MDN-Object-Tutorial/index.html b/week-6/MDN-Object-Tutorial/index.html new file mode 100644 index 0000000..28fd162 --- /dev/null +++ b/week-6/MDN-Object-Tutorial/index.html @@ -0,0 +1,14 @@ + + + + + + + MDN Object Tutorial + + +

Hello There! Press F12 For the Solution

+ + + + \ No newline at end of file diff --git a/week-6/MDN-Object-Tutorial/main.js b/week-6/MDN-Object-Tutorial/main.js new file mode 100644 index 0000000..771efd9 --- /dev/null +++ b/week-6/MDN-Object-Tutorial/main.js @@ -0,0 +1,59 @@ +const person = { + name: ['Bob', 'Smith'], + age: 32, + bio() { + console.log(`${this.name[0]} ${this.name[1]} is ${this.age} years old.`); + }, + introduceSelf() { + console.log(`Hi! I'm ${this.name[0]}.`); + } + +}; +const person1 = { + name: 'Chris', + introduceSelf() { + console.log(`Hi! I'm ${this.name}.`); + } +} + +const person2 = { + name: 'Deepti', + introduceSelf() { + console.log(`Hi! I'm ${this.name}.`); + } +} + +function createPerson(name) { + const obj = {}; + obj.name = name; + obj.introduceSelf = function() { + console.log(`Hi! I'm ${this.name}.`); + } + return obj; +} +function Person(name) { + this.name = name; + this.introduceSelf = function() { + console.log(`Hi! I'm ${this.name}.`); + } +} + +const salva = new Person('Salva'); +salva.name; +salva.introduceSelf(); + +const frankie = new Person('Frankie'); +frankie.name; +frankie.introduceSelf(); + +const myDiv = document.createElement('div'); +const myVideo = document.querySelector('video'); + + + +const myDataName = 'height'; +const myDataValue = '1.75m'; +person[myDataName] = myDataValue; + + +