From 8549a1f2446c207034a807570e996b84bf8fabac Mon Sep 17 00:00:00 2001 From: Rahime YILDIZ <50872722+rcmzyldz@users.noreply.github.com> Date: Wed, 10 Jul 2019 21:50:44 +0200 Subject: [PATCH 01/26] updated --- Week1/exercise/w1/index.html | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Week1/exercise/w1/index.html b/Week1/exercise/w1/index.html index 5a88074db..7963d100d 100644 --- a/Week1/exercise/w1/index.html +++ b/Week1/exercise/w1/index.html @@ -1,4 +1,4 @@ - +!DOCTYPE html> @@ -13,7 +13,9 @@

JS2 - exercise 1

- lights +

+ lights
+
@@ -28,11 +30,11 @@

Todos:

  • Learn javascript
  • Take over the world
  • - +
    - + From 8dde85d96ba72be450cce2cf292dc849723ed607 Mon Sep 17 00:00:00 2001 From: Rahime YILDIZ <50872722+rcmzyldz@users.noreply.github.com> Date: Wed, 10 Jul 2019 21:52:42 +0200 Subject: [PATCH 02/26] I have done exercises --- Week1/exercise/w1/index.js | 45 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/Week1/exercise/w1/index.js b/Week1/exercise/w1/index.js index fcea7032e..ef93b557a 100644 --- a/Week1/exercise/w1/index.js +++ b/Week1/exercise/w1/index.js @@ -1,5 +1,15 @@ + + console.log('Hack your future Belgium!'); + + +// select button byıd + +// add event lıstener to that button +// + + // EXERCISE 1 // 1a: create a function called "changeHeader", put a console.log() inside this function to test @@ -11,9 +21,15 @@ console.log('Hack your future Belgium!'); // 1c: change the inner html of the header element to your name +const h1 = document.querySelector("h1") +function changeHeader() { + console.log("test"); + h1.innerHTML ="Rahime"; +} -// ====================================== // +document.getElementById("btn-changeHeader").addEventListener("click", changeHeader); +// ====================================== // // EXERCISE 2 @@ -30,11 +46,19 @@ console.log('Hack your future Belgium!'); // 2e: to change the image: assign the imageInputValue to the image src -// ====================================== // +function changeImage() { + console.log("test2"); + const imageToChange = document.querySelector("img"); + const imageInputValue = document.querySelector("#imageInput").value; + imageToChange.src = imageInputValue; +} + document.getElementById("btn-changeImage").addEventListener("click", changeImage); +// ====================================== // // Exercise 3: + // 3a: select "add todo" button & add click event listener to execute addTodo() function on click event // 3b: define addTodo() function, in this function: @@ -48,3 +72,20 @@ console.log('Hack your future Belgium!'); // 3f: set created
  • element innerHtml to todoInput value // 3g: add
  • element to todoList + + + var btn = document.getElementById("btn-addTodo");//a + + btn.addEventListener("click", addTodo);//b + + function addTodo (){ + + var myList = document.getElementById("todoList"); + var myInput = document.getElementById("todoInput").value; + console.log(myInput); + + var newItem = document.createElement("li"); + newItem.innerHTML= myInput; + myList.appendChild(newItem); + + } From 9d29ae6962a9bba76ac32795ce44353879b39fe4 Mon Sep 17 00:00:00 2001 From: Rahime YILDIZ <50872722+rcmzyldz@users.noreply.github.com> Date: Sun, 14 Jul 2019 02:32:29 +0200 Subject: [PATCH 03/26] Update app.js --- Week1/homework/app.js | 137 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 132 insertions(+), 5 deletions(-) diff --git a/Week1/homework/app.js b/Week1/homework/app.js index a9b5f75d8..79673e67a 100644 --- a/Week1/homework/app.js +++ b/Week1/homework/app.js @@ -1,11 +1,138 @@ 'use strict'; { - const bookTitles = [ // Replace with your own book titles - 'harry_potter_chamber_secrets', - ]; + const bookTitles = [ + + 'pride_and_prejudice', + 'animal_farm', + 'alice_in_wonderland', + 'the_last_leaf', + 'the_picture_of_dorian_gray', + 'hamlet', + 'madame_bovary', + 'canterbury_tales', + 'emma', + 'sense_and_sensibility' + + ]; + + // Replace with your own code + - // Replace with your own code - console.log(bookTitles); } +// make an object + +const myBookDetailsObj = { + pride_and_prejudice: { + title: 'Pride and Prejudice', + language: 'English', + author: 'Jane Austen', + + }, + + animal_farm: { + title: 'Animal Farm', + language: 'English', + author: 'George Orwell', + + }, + + alice_in_wonderland: { + title: 'Alice in Wonderland', + language: 'English', + author: 'Lewis Carrol', + }, + + the_last_leaf: { + title: 'The Last Leaf', + language: 'English', + author: 'O.Henry', + }, + + the_picture_of_dorian_gray: { + title: 'The Picure of Dorian Gray', + language: 'English', + author: 'Oscar Wilde', + }, + + hamlet: { + title: 'Hamlet', + language: 'English', + author: 'William Shakespeare', + }, + + madame_bovary: { + title: 'Madame Bovary', + language: 'French', + author: 'Gustave Flaubert', + }, + + canterbury_tales: { + title: 'Canterbury Tales', + language: 'English', + author: 'Geoffrey Chaucer', + }, + + anna_karenina: { + title: 'Anna Karenina', + language: 'Russian', + author: 'Leo Tolstoy', + }, + + sense_and_sensibility: { + title: 'Sence and Sensibility', + language: 'English', + author: 'Jane Austen', + } + +}; + +const bookCoverImagesObj = { + pride_and_prejudice: './assets/pride_and_prejudice.jpg', + animal_farm: './assets/animal_farm.jpg', + alice_in_wonderland: './assets/alice_in_wonderland.jpg', + the_last_leaf: './assets/the_last_leaf.jpg', + the_picture_of_dorian_gray: './assets/the_picture_of_dorian_gray.jpg', + hamlet: './assets/hamlet.jpg', + madame_bovary: './assets/madame_bovary.jpg', + canterbury_tales: './assets/the_canterbury_tales.jpg', + anna_karenina: './assets/anna_karenina.jpg', + sense_and_sensibility: './assets/sense_and_sensibility.jpg' + +} + + +function myFavouredBooks() { + var bookContainer = document.createElement('h1'); + h1 = document.createTextNode('My Favoured Books'); + document.getElementsByTagName('body')[0].appendChild('h1'); + + + myBookTitles = document.createElement('ul'); + + + for (var key in myBookDetailsObj); + + const listItem = document.createElement('li'); + + listElement.appendChild(listItem); + const title = document.createElement('h2'); + header.innerHTML = myBookDetailsObj[key].title; + myBookTitles.appendChild('title'); + + const images = document.createElement("img"); + images.setAttribute("src", bookCoverImagesObj[key]); + images.setAttribute("alt", key); + listItem.appendChild(images); + + const author = document.createElement('h3'); + author.innerHTML = "Author: " + myBookDetailsObj[key].author; + listItem.appendChild(author); + + const language = document.createElement('h3'); + language.innerHTML = "Language: " + myBookDetailsObj[key].language; + listItem.appendChild(language); + + +}; From b6531c8d571fffac8daaaa4250bc9cd0be463340 Mon Sep 17 00:00:00 2001 From: Rahime YILDIZ <50872722+rcmzyldz@users.noreply.github.com> Date: Sun, 14 Jul 2019 02:35:32 +0200 Subject: [PATCH 04/26] Update index.html --- Week1/homework/index.html | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Week1/homework/index.html b/Week1/homework/index.html index b22147cd1..d13f9aa5d 100644 --- a/Week1/homework/index.html +++ b/Week1/homework/index.html @@ -1 +1,16 @@ - \ No newline at end of file + + + + + + + + + My Favoured Books + + + + + + + From 37fc370a67da0386df9f96daf9e7e655810cc903 Mon Sep 17 00:00:00 2001 From: Rahime YILDIZ <50872722+rcmzyldz@users.noreply.github.com> Date: Sun, 21 Jul 2019 10:25:55 +0200 Subject: [PATCH 05/26] Add files via upload --- Week2/exercises2.html | 15 ++++++++++ Week2/exercises2.js | 68 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 Week2/exercises2.html create mode 100644 Week2/exercises2.js diff --git a/Week2/exercises2.html b/Week2/exercises2.html new file mode 100644 index 000000000..c3210134f --- /dev/null +++ b/Week2/exercises2.html @@ -0,0 +1,15 @@ + + + + + + + + Document + + + + + + + \ No newline at end of file diff --git a/Week2/exercises2.js b/Week2/exercises2.js new file mode 100644 index 000000000..5a163a61c --- /dev/null +++ b/Week2/exercises2.js @@ -0,0 +1,68 @@ +//first exercise + +const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]; + +function firstElement(n) { + + return arr.slice(0, n); + +} + +firstElement = array[0]; + +console.log(firstElement(3)); +console.log(arr[num]); +// I cannot finish it + + +//Second exercise + +var num = window.prompt(); +var str = num.toString(); +var result = [str[0]]; + +for (var i = 1; i < str.length; i++) { + if (str[i - 1] % 2 === 0 && str[i] % 2 === 0) { + result.push('-', str[i]); + } else { + result.push(str[i]); + } +} +console.log(result.join('')); + +//third exercise + +var arr1 = [3, 'a', 'a', 'a', 2, 3, 'a', 3, 'a', 2, 4, 9, 3]; +var mf = 1; +var m = 0; +var item; +for (var i = 0; i < arr1.length; i++) { + for (var j = i; j < arr1.length; j++) { + if (arr1[i] == arr1[j]) + m++; + if (mf < m) { + mf = m; + item = arr1[i]; + } + } + m = 0; +} +console.log(item + " ( " + mf + " times ) "); + +//fourth + +var str = 'c'; +const UPPER = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; +const LOWER = 'abcdefghijklmnopqrstuvwxyz'; +const result = []; + +for (let i = 0; i < str.length; i++) { + if (UPPER.includes(str[i])) { + result.push(str[i].toLowerCase()); + } else if (LOWER.includes(str[i])) { + result.push(str[i].toUpperCase()); + } else { + result.push(str[i]); + } +} +console.log(result.join('')); \ No newline at end of file From b9d4fd8e3fea339e01b68ceee5cf4d86cd9b85be Mon Sep 17 00:00:00 2001 From: Rahime YILDIZ <50872722+rcmzyldz@users.noreply.github.com> Date: Sat, 27 Jul 2019 21:29:51 +0200 Subject: [PATCH 06/26] Add files via upload --- Week2/JSON.html | 15 +++++++++++++++ Week2/json.js | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 Week2/JSON.html create mode 100644 Week2/json.js diff --git a/Week2/JSON.html b/Week2/JSON.html new file mode 100644 index 000000000..26dfb8280 --- /dev/null +++ b/Week2/JSON.html @@ -0,0 +1,15 @@ + + + + + + + + Document + + + + + + + \ No newline at end of file diff --git a/Week2/json.js b/Week2/json.js new file mode 100644 index 000000000..44dc66bdb --- /dev/null +++ b/Week2/json.js @@ -0,0 +1,40 @@ +'use strict' + +//Write a JavaScript function to check if an object contains given property. + +var myBooks = { + a: "Hamlet", + b: "Last Leaf", + c: "Canterbury Tales" +}; +var isHasProperty = (myBooks, a, b, c) => { + + if (myBooks.hasOwnProperty('a')) { + console.log('Yes, I have ' + a); + } else { + console.log('No, I do not have ' + a + 'book'); + }; + +}; +console.log(isHasProperty(myBooks, 'hamlet')); + +// Write a JavaScript program to get the length (amount of keys) of a JavaScript object. + +var student = { + name: "John", + sclass: "IV", + no: 12 +}; + +console.log(Object.keys(student).length); + +//Write a JavaScript program to create a Clock. Console, every second :”14:37:42”,”14:37:43", “14:37:44”, "14:37:45" + + +setInterval(function() { + + var d = new Date(); + + console.log(d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds()); + +}, 1000); \ No newline at end of file From 057f320308683311dbb30a642a224223630e4f6c Mon Sep 17 00:00:00 2001 From: Rahime YILDIZ <50872722+rcmzyldz@users.noreply.github.com> Date: Sat, 27 Jul 2019 23:48:03 +0200 Subject: [PATCH 07/26] Add files via upload --- Week2/maartjes-work.js | 73 ++++++++++++++++++++++++++++++++++++++++++ Week2/map-filter.js | 17 ++++++++++ 2 files changed, 90 insertions(+) create mode 100644 Week2/maartjes-work.js create mode 100644 Week2/map-filter.js diff --git a/Week2/maartjes-work.js b/Week2/maartjes-work.js new file mode 100644 index 000000000..b38233ee0 --- /dev/null +++ b/Week2/maartjes-work.js @@ -0,0 +1,73 @@ +'use strict'; + +const monday = [{ + name: 'Write a summary HTML/CSS', + duration: 180, + }, + { + name: 'Some web development', + duration: 120, + }, + { + name: 'Fix homework for class10', + duration: 20, + }, + { + name: 'Talk to a lot of people', + duration: 200, + }, +]; + +const tuesday = [{ + name: 'Keep writing summary', + duration: 240, + }, + { + name: 'Some more web development', + duration: 180, + }, + { + name: 'Staring out the window', + duration: 10, + }, + { + name: 'Talk to a lot of people', + duration: 200, + }, + { + name: 'Look at application assignments new students', + duration: 40, + }, +]; + +const maartjesTasks = monday.concat(tuesday); +const maartjesHourlyRate = 20; + +function computeEarnings(tasks, hourlyRate) { + // Replace this comment and the next line with your code + const hourlyTasks = tasks + .map(task => task.duration / 60) //Map the tasks to durations in hours. + .filter(taskDuration => taskDuration >= 2) //Filter out everything that took less than two hours + .map(duration => duration * hourlyRate) //Multiply the each duration by a per-hour rate for billing + .reduce((acc, salary) => acc + salary) + .toFixed(2); //Output a formatted Euro amount, rounded to Euro cents + + return taskDurations; +} + + + + +// eslint-disable-next-line no-unused-vars +const earnings = computeEarnings(maartjesTasks, maartjesHourlyRate); + +// add code to convert `earnings` to a string rounded to two decimals (euro cents) + +console.log(`Maartje has earned €${earnings}`); + +// Do not change or remove anything below this line +module.exports = { + maartjesTasks, + maartjesHourlyRate, + computeEarnings, +}; \ No newline at end of file diff --git a/Week2/map-filter.js b/Week2/map-filter.js new file mode 100644 index 000000000..fe346b996 --- /dev/null +++ b/Week2/map-filter.js @@ -0,0 +1,17 @@ +'use strict'; + +function doubleOddNumbers(numbers) { + + var newArray = numbers.filter(num => num % 2 === 1).map(num => num * 2) + return newArray; + +} + +const myNumbers = [1, 2, 3, 4]; +console.log(doubleOddNumbers(myNumbers)); + +// Do not change or remove anything below this line +module.exports = { + myNumbers, + doubleOddNumbers, +}; \ No newline at end of file From a83820f56002b6a6a62aced933ea2906f37ee764 Mon Sep 17 00:00:00 2001 From: Rahime YILDIZ <50872722+rcmzyldz@users.noreply.github.com> Date: Fri, 2 Aug 2019 01:52:43 +0200 Subject: [PATCH 08/26] Add files via upload --- Week3/step2-1.js | 14 ++++++++++++ Week3/step2-2.js | 37 +++++++++++++++++++++++++++++++ Week3/step2-3.js | 52 ++++++++++++++++++++++++++++++++++++++++++++ Week3/step2-4.js | 12 ++++++++++ Week3/step2-5.js | 24 ++++++++++++++++++++ Week3/step2-6.js | 34 +++++++++++++++++++++++++++++ Week3/step2-7.js | 33 ++++++++++++++++++++++++++++ Week3/step3-bonus.js | 15 +++++++++++++ Week3/step3.js | 15 +++++++++++++ 9 files changed, 236 insertions(+) create mode 100644 Week3/step2-1.js create mode 100644 Week3/step2-2.js create mode 100644 Week3/step2-3.js create mode 100644 Week3/step2-4.js create mode 100644 Week3/step2-5.js create mode 100644 Week3/step2-6.js create mode 100644 Week3/step2-7.js create mode 100644 Week3/step3-bonus.js create mode 100644 Week3/step3.js diff --git a/Week3/step2-1.js b/Week3/step2-1.js new file mode 100644 index 000000000..77717b20e --- /dev/null +++ b/Week3/step2-1.js @@ -0,0 +1,14 @@ +'use strict'; + +function foo(func) { + return func(); +} + +function bar() { + console.log('Hello, I am bar!'); +} + +foo(bar); + +// Do not change or remove anything below this line +module.exports = foo; \ No newline at end of file diff --git a/Week3/step2-2.js b/Week3/step2-2.js new file mode 100644 index 000000000..8fcfba9ba --- /dev/null +++ b/Week3/step2-2.js @@ -0,0 +1,37 @@ +'use strict'; + +function threeFive(startIndex, stopIndex, threeCallback, fiveCallback) { + const numbers = []; + for (let i = startIndex; i <= stopIndex; i++) { + numbers.push(i); + } + + numbers.map(x => { + if (x % 5 === 0 && x % 3 === 0) { + threeCallback(x); + fiveCallback(x) + } else if (x % 3 === 0) { + threeCallback(x) + } else if (x % 5 === 0) { + fiveCallback(x) + } + }) + + // Replace this comment and the next line with your code + console.log(startIndex, stopIndex, threeCallback, fiveCallback, numbers); +} + +function sayThree(number) { + + console.log(number + "is dividable by 3"); +} + +function sayFive(number) { + // Replace this comment and the next line with your code + console.log(number + "is dividable by 5"); +} + +threeFive(10, 15, sayThree, sayFive); + +// Do not change or remove anything below this line +module.exports = threeFive; \ No newline at end of file diff --git a/Week3/step2-3.js b/Week3/step2-3.js new file mode 100644 index 000000000..7859a8292 --- /dev/null +++ b/Week3/step2-3.js @@ -0,0 +1,52 @@ +'use strict'; + +// Use a 'for' loop +function repeatStringNumTimesWithFor(str, num) { + // eslint-disable-next-line prefer-const + let result = ''; + + for (let i = num; i > 0; i--) { + result += str; + } + + return result; +} + +console.log('for', repeatStringNumTimesWithFor('abc', 3)); + +// Use a 'while' loop +function repeatStringNumTimesWithWhile(str, num) { + // eslint-disable-next-line prefer-const + let result = ''; + + while (num > 0) { + result += str; + num--; + } + + return result; +} + +console.log('while', repeatStringNumTimesWithWhile('abc', 3)); + +// Use a 'do...while' loop +function repeatStringNumTimesWithDoWhile(str, num) { + // eslint-disable-next-line prefer-const + let result = ''; + do { + result += str; + num--; + } while (num > 0); + + + return result; +} + +console.log('do-while', repeatStringNumTimesWithDoWhile('abc', 3)); + +// Do not change or remove anything below this line +module.exports = { + repeatStringNumTimesWithFor, + repeatStringNumTimesWithWhile, + repeatStringNumTimesWithDoWhile, +}; \ No newline at end of file diff --git a/Week3/step2-4.js b/Week3/step2-4.js new file mode 100644 index 000000000..be4379e76 --- /dev/null +++ b/Week3/step2-4.js @@ -0,0 +1,12 @@ +'use strict'; + +function Dog() { + this.name = 'MoonLight'; + this.color = 'blonde'; + this.numLegs = 4; +} + +const hound = new Dog(); + +// Do not change or remove anything below this line +module.exports = hound; \ No newline at end of file diff --git a/Week3/step2-5.js b/Week3/step2-5.js new file mode 100644 index 000000000..0961a30b0 --- /dev/null +++ b/Week3/step2-5.js @@ -0,0 +1,24 @@ +'use strict'; + +function multiplyAll(arr) { + // eslint-disable-next-line + let product = 1; + + for (var i = 0; i < arr.length; i++) { + for (var j = 0; j < arr[i].length; j++) { + product = product * arr[i][j]; + } + + return product; + } + + const result = multiplyAll([ + [1, 2], + [3, 4], + [5, 6] + ]); + console.log(result); // 720 + + // Do not change or remove anything below this line + module.exports = multiplyAll; +} \ No newline at end of file diff --git a/Week3/step2-6.js b/Week3/step2-6.js new file mode 100644 index 000000000..0e340b87f --- /dev/null +++ b/Week3/step2-6.js @@ -0,0 +1,34 @@ +'use strict'; + +const arr2d = [ + [1, 2], + [3, 4], + [5, 6] +]; +const arr3d = [ + [ + [1, 2], + [3, 4] + ], + [ + [5, 6], + [7, 8] + ] +]; + +function flattenArray2d(arr) { + return arr.flat(); +} + +function flattenArray3d(arr) { + return arr.flat(2); + +} +console.log(flattenArray2d(arr2d)); // -> [1, 2, 3, 4, 5, 6] +console.log(flattenArray3d(arr3d)); // -> [1, 2, 3, 4, 5, 6, 7, 8] + +// Do not change or remove anything below this line +module.exports = { + flattenArray2d, + flattenArray3d, +}; \ No newline at end of file diff --git a/Week3/step2-7.js b/Week3/step2-7.js new file mode 100644 index 000000000..1d392567f --- /dev/null +++ b/Week3/step2-7.js @@ -0,0 +1,33 @@ +'use strict'; + +const x = 9; + +function f1(val) { + val = val + 1; + return val; +} + +f1(x); + +console.log(x); + +const y = { x: 9 }; + +function f2(val) { + val.x = val.x + 1; + return val; +} + +f2(y); + +console.log(y); + +// Add your explanation as a comment here +/* +Function is called by directly passing the reference/address of the variable + as the argument. Changing the argument inside the function + affect the variable passed from outside the function. + In Javascript objects and arrays follows pass by reference. + so if we are passing object or array as an argument to the method, + then there is a possibility that value of the object can change. + */ \ No newline at end of file diff --git a/Week3/step3-bonus.js b/Week3/step3-bonus.js new file mode 100644 index 000000000..52d64618c --- /dev/null +++ b/Week3/step3-bonus.js @@ -0,0 +1,15 @@ +'use strict'; + +function makeUnique(arr) { + + let myArray = ['a', 'b', 'c', 'd', 'a', 'e', 'f', 'c']; + + unique = [...new Set(myArray)]; + return result; + +}; +const uniqueValues = makeUnique(values); +console.log(uniqueValues); + +// Do not change or remove anything below this line +module.exports = makeUnique; \ No newline at end of file diff --git a/Week3/step3.js b/Week3/step3.js new file mode 100644 index 000000000..d36e32ce4 --- /dev/null +++ b/Week3/step3.js @@ -0,0 +1,15 @@ +'use strict'; + +function createBase(base) { + // Replace this comment and the next line with your code + return + console.log(base); +} + +const addSix = createBase(6); + +console.log(addSix(10)); // returns 16 +console.log(addSix(21)); // returns 27 + +// Do not change or remove anything below this line +module.exports = createBase; \ No newline at end of file From 6ca7d80ad62a76843480bfa3af90067a9823f3f3 Mon Sep 17 00:00:00 2001 From: Rahime YILDIZ <50872722+rcmzyldz@users.noreply.github.com> Date: Fri, 2 Aug 2019 01:55:37 +0200 Subject: [PATCH 09/26] Update step2-1.js --- Week3/homework/step2-1.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Week3/homework/step2-1.js b/Week3/homework/step2-1.js index d5699882c..8046af7d6 100644 --- a/Week3/homework/step2-1.js +++ b/Week3/homework/step2-1.js @@ -1,13 +1,11 @@ 'use strict'; function foo(func) { - // What to do here? - // Replace this comment and the next line with your code - console.log(func); + return func(); } function bar() { - console.log('Hello, I am bar!'); + console.log('Hello, I am bar!'); } foo(bar); From 060a37c40e38fa55ec1eb2291b0519b74fa80eea Mon Sep 17 00:00:00 2001 From: Rahime YILDIZ <50872722+rcmzyldz@users.noreply.github.com> Date: Fri, 2 Aug 2019 01:56:24 +0200 Subject: [PATCH 10/26] Update step2-2.js --- Week3/homework/step2-2.js | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/Week3/homework/step2-2.js b/Week3/homework/step2-2.js index dcd135040..80e7e6b39 100644 --- a/Week3/homework/step2-2.js +++ b/Week3/homework/step2-2.js @@ -1,20 +1,34 @@ 'use strict'; function threeFive(startIndex, stopIndex, threeCallback, fiveCallback) { - const numbers = []; + const numbers = []; + for (let i = startIndex; i <= stopIndex; i++) { + numbers.push(i); + } - // Replace this comment and the next line with your code - console.log(startIndex, stopIndex, threeCallback, fiveCallback, numbers); + numbers.map(x => { + if (x % 5 === 0 && x % 3 === 0) { + threeCallback(x); + fiveCallback(x) + } else if (x % 3 === 0) { + threeCallback(x) + } else if (x % 5 === 0) { + fiveCallback(x) + } + }) + + // Replace this comment and the next line with your code + console.log(startIndex, stopIndex, threeCallback, fiveCallback, numbers); } function sayThree(number) { - // Replace this comment and the next line with your code - console.log(number); + + console.log(number + "is dividable by 3"); } function sayFive(number) { - // Replace this comment and the next line with your code - console.log(number); + // Replace this comment and the next line with your code + console.log(number + "is dividable by 5"); } threeFive(10, 15, sayThree, sayFive); From edcc5f211bad39d1fb24b825f9a755f1d2097fef Mon Sep 17 00:00:00 2001 From: Rahime YILDIZ <50872722+rcmzyldz@users.noreply.github.com> Date: Fri, 2 Aug 2019 01:57:22 +0200 Subject: [PATCH 11/26] Update step2-3.js --- Week3/homework/step2-3.js | 41 ++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/Week3/homework/step2-3.js b/Week3/homework/step2-3.js index 00845c5eb..000b8ffcd 100644 --- a/Week3/homework/step2-3.js +++ b/Week3/homework/step2-3.js @@ -2,46 +2,51 @@ // Use a 'for' loop function repeatStringNumTimesWithFor(str, num) { - // eslint-disable-next-line prefer-const - let result = ''; + // eslint-disable-next-line prefer-const + let result = ''; - // Replace this comment and the next line with your code - console.log(str, num, result); + for (let i = num; i > 0; i--) { + result += str; + } - return result; + return result; } console.log('for', repeatStringNumTimesWithFor('abc', 3)); // Use a 'while' loop function repeatStringNumTimesWithWhile(str, num) { - // eslint-disable-next-line prefer-const - let result = ''; + // eslint-disable-next-line prefer-const + let result = ''; - // Replace this comment and the next line with your code - console.log(str, num, result); + while (num > 0) { + result += str; + num--; + } - return result; + return result; } console.log('while', repeatStringNumTimesWithWhile('abc', 3)); // Use a 'do...while' loop function repeatStringNumTimesWithDoWhile(str, num) { - // eslint-disable-next-line prefer-const - let result = ''; + // eslint-disable-next-line prefer-const + let result = ''; + do { + result += str; + num--; + } while (num > 0); - // Replace this comment and the next line with your code - console.log(str, num, result); - return result; + return result; } console.log('do-while', repeatStringNumTimesWithDoWhile('abc', 3)); // Do not change or remove anything below this line module.exports = { - repeatStringNumTimesWithFor, - repeatStringNumTimesWithWhile, - repeatStringNumTimesWithDoWhile, + repeatStringNumTimesWithFor, + repeatStringNumTimesWithWhile, + repeatStringNumTimesWithDoWhile, }; From 2c7893113cf6133972beed6d412138767cafc3e6 Mon Sep 17 00:00:00 2001 From: Rahime YILDIZ <50872722+rcmzyldz@users.noreply.github.com> Date: Fri, 2 Aug 2019 01:58:13 +0200 Subject: [PATCH 12/26] Update step2-4.js --- Week3/homework/step2-4.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Week3/homework/step2-4.js b/Week3/homework/step2-4.js index b11b1dcb6..efc64a405 100644 --- a/Week3/homework/step2-4.js +++ b/Week3/homework/step2-4.js @@ -1,7 +1,9 @@ 'use strict'; function Dog() { - // add your code here + this.name = 'MoonLight'; + this.color = 'blonde'; + this.numLegs = 4; } const hound = new Dog(); From 307047745b9147c5140ae9e4b1ee6d6ed6f58cac Mon Sep 17 00:00:00 2001 From: Rahime YILDIZ <50872722+rcmzyldz@users.noreply.github.com> Date: Fri, 2 Aug 2019 01:58:53 +0200 Subject: [PATCH 13/26] Update step2-5.js --- Week3/homework/step2-5.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/Week3/homework/step2-5.js b/Week3/homework/step2-5.js index cbb54fa1d..7f59cdbc9 100644 --- a/Week3/homework/step2-5.js +++ b/Week3/homework/step2-5.js @@ -1,17 +1,24 @@ 'use strict'; function multiplyAll(arr) { - // eslint-disable-next-line - let product = 1; + // eslint-disable-next-line + let product = 1; - // Replace this comment and the next line with your code - console.log(arr, product); + for (var i = 0; i < arr.length; i++) { + for (var j = 0; j < arr[i].length; j++) { + product = product * arr[i][j]; + } - return product; -} + return product; + } -const result = multiplyAll([[1, 2], [3, 4], [5, 6]]); -console.log(result); // 720 + const result = multiplyAll([ + [1, 2], + [3, 4], + [5, 6] + ]); + console.log(result); // 720 -// Do not change or remove anything below this line -module.exports = multiplyAll; + // Do not change or remove anything below this line + module.exports = multiplyAll; +} From e5683bad6bca6a96543d059702f497cee59c23cf Mon Sep 17 00:00:00 2001 From: Rahime YILDIZ <50872722+rcmzyldz@users.noreply.github.com> Date: Fri, 2 Aug 2019 01:59:33 +0200 Subject: [PATCH 14/26] Update step2-6.js --- Week3/homework/step2-6.js | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/Week3/homework/step2-6.js b/Week3/homework/step2-6.js index ffe95b9f7..ff774fb90 100644 --- a/Week3/homework/step2-6.js +++ b/Week3/homework/step2-6.js @@ -1,23 +1,34 @@ 'use strict'; -const arr2d = [[1, 2], [3, 4], [5, 6]]; -const arr3d = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]; +const arr2d = [ + [1, 2], + [3, 4], + [5, 6] +]; +const arr3d = [ + [ + [1, 2], + [3, 4] + ], + [ + [5, 6], + [7, 8] + ] +]; function flattenArray2d(arr) { - // Replace this comment and the next line with your code - console.log(arr); + return arr.flat(); } function flattenArray3d(arr) { - // Replace this comment and the next line with your code - console.log(arr); -} + return arr.flat(2); +} console.log(flattenArray2d(arr2d)); // -> [1, 2, 3, 4, 5, 6] console.log(flattenArray3d(arr3d)); // -> [1, 2, 3, 4, 5, 6, 7, 8] // Do not change or remove anything below this line module.exports = { - flattenArray2d, - flattenArray3d, + flattenArray2d, + flattenArray3d, }; From a7c9e2cc858ed92f9c5035fcf3372a7c558764f5 Mon Sep 17 00:00:00 2001 From: Rahime YILDIZ <50872722+rcmzyldz@users.noreply.github.com> Date: Fri, 2 Aug 2019 02:00:14 +0200 Subject: [PATCH 15/26] Update step2-7.js --- Week3/homework/step2-7.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Week3/homework/step2-7.js b/Week3/homework/step2-7.js index 3e72e8551..03d418964 100644 --- a/Week3/homework/step2-7.js +++ b/Week3/homework/step2-7.js @@ -1,9 +1,10 @@ 'use strict'; const x = 9; + function f1(val) { - val = val + 1; - return val; + val = val + 1; + return val; } f1(x); @@ -11,9 +12,10 @@ f1(x); console.log(x); const y = { x: 9 }; + function f2(val) { - val.x = val.x + 1; - return val; + val.x = val.x + 1; + return val; } f2(y); @@ -21,3 +23,11 @@ f2(y); console.log(y); // Add your explanation as a comment here +/* +Function is called by directly passing the reference/address of the variable + as the argument. Changing the argument inside the function + affect the variable passed from outside the function. + In Javascript objects and arrays follows pass by reference. + so if we are passing object or array as an argument to the method, + then there is a possibility that value of the object can change. + */ From 76cb2f69b590fe2acba4d1f63075147659d53da4 Mon Sep 17 00:00:00 2001 From: Rahime YILDIZ <50872722+rcmzyldz@users.noreply.github.com> Date: Fri, 2 Aug 2019 02:00:59 +0200 Subject: [PATCH 16/26] Update step3-bonus.js --- Week3/homework/step3-bonus.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Week3/homework/step3-bonus.js b/Week3/homework/step3-bonus.js index 917091d61..2e2afb9f2 100644 --- a/Week3/homework/step3-bonus.js +++ b/Week3/homework/step3-bonus.js @@ -1,12 +1,13 @@ 'use strict'; -const values = ['a', 'b', 'c', 'd', 'a', 'e', 'f', 'c']; - function makeUnique(arr) { - // Replace this comment and the next line with your code - console.log(arr); -} + let myArray = ['a', 'b', 'c', 'd', 'a', 'e', 'f', 'c']; + + unique = [...new Set(myArray)]; + return result; + +}; const uniqueValues = makeUnique(values); console.log(uniqueValues); From c1e5d4501c1bd24045c12fde15d347a8c7d4230d Mon Sep 17 00:00:00 2001 From: Rahime YILDIZ <50872722+rcmzyldz@users.noreply.github.com> Date: Fri, 2 Aug 2019 02:01:40 +0200 Subject: [PATCH 17/26] Update step3.js --- Week3/homework/step3.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Week3/homework/step3.js b/Week3/homework/step3.js index 292724bf4..3954ec9eb 100644 --- a/Week3/homework/step3.js +++ b/Week3/homework/step3.js @@ -1,8 +1,9 @@ 'use strict'; function createBase(base) { - // Replace this comment and the next line with your code - console.log(base); + // Replace this comment and the next line with your code + return + console.log(base); } const addSix = createBase(6); From f1b203e35565cf4f8c339c701693ff58d032310b Mon Sep 17 00:00:00 2001 From: Rahime YILDIZ <50872722+rcmzyldz@users.noreply.github.com> Date: Fri, 2 Aug 2019 02:14:16 +0200 Subject: [PATCH 18/26] Delete step3.js --- Week3/step3.js | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 Week3/step3.js diff --git a/Week3/step3.js b/Week3/step3.js deleted file mode 100644 index d36e32ce4..000000000 --- a/Week3/step3.js +++ /dev/null @@ -1,15 +0,0 @@ -'use strict'; - -function createBase(base) { - // Replace this comment and the next line with your code - return - console.log(base); -} - -const addSix = createBase(6); - -console.log(addSix(10)); // returns 16 -console.log(addSix(21)); // returns 27 - -// Do not change or remove anything below this line -module.exports = createBase; \ No newline at end of file From e00b8d83b117bd3ddbcb35c83629262a50ac7ba7 Mon Sep 17 00:00:00 2001 From: Rahime YILDIZ <50872722+rcmzyldz@users.noreply.github.com> Date: Fri, 2 Aug 2019 02:14:30 +0200 Subject: [PATCH 19/26] Delete step3-bonus.js --- Week3/step3-bonus.js | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 Week3/step3-bonus.js diff --git a/Week3/step3-bonus.js b/Week3/step3-bonus.js deleted file mode 100644 index 52d64618c..000000000 --- a/Week3/step3-bonus.js +++ /dev/null @@ -1,15 +0,0 @@ -'use strict'; - -function makeUnique(arr) { - - let myArray = ['a', 'b', 'c', 'd', 'a', 'e', 'f', 'c']; - - unique = [...new Set(myArray)]; - return result; - -}; -const uniqueValues = makeUnique(values); -console.log(uniqueValues); - -// Do not change or remove anything below this line -module.exports = makeUnique; \ No newline at end of file From 7ddc054442464ed47bd673bb9953ee7cfda0b76b Mon Sep 17 00:00:00 2001 From: Rahime YILDIZ <50872722+rcmzyldz@users.noreply.github.com> Date: Fri, 2 Aug 2019 02:14:40 +0200 Subject: [PATCH 20/26] Delete step2-7.js --- Week3/step2-7.js | 33 --------------------------------- 1 file changed, 33 deletions(-) delete mode 100644 Week3/step2-7.js diff --git a/Week3/step2-7.js b/Week3/step2-7.js deleted file mode 100644 index 1d392567f..000000000 --- a/Week3/step2-7.js +++ /dev/null @@ -1,33 +0,0 @@ -'use strict'; - -const x = 9; - -function f1(val) { - val = val + 1; - return val; -} - -f1(x); - -console.log(x); - -const y = { x: 9 }; - -function f2(val) { - val.x = val.x + 1; - return val; -} - -f2(y); - -console.log(y); - -// Add your explanation as a comment here -/* -Function is called by directly passing the reference/address of the variable - as the argument. Changing the argument inside the function - affect the variable passed from outside the function. - In Javascript objects and arrays follows pass by reference. - so if we are passing object or array as an argument to the method, - then there is a possibility that value of the object can change. - */ \ No newline at end of file From b3e8c9c2c61494264739c87acf0d26b86933cf2a Mon Sep 17 00:00:00 2001 From: Rahime YILDIZ <50872722+rcmzyldz@users.noreply.github.com> Date: Fri, 2 Aug 2019 02:14:49 +0200 Subject: [PATCH 21/26] Delete step2-6.js --- Week3/step2-6.js | 34 ---------------------------------- 1 file changed, 34 deletions(-) delete mode 100644 Week3/step2-6.js diff --git a/Week3/step2-6.js b/Week3/step2-6.js deleted file mode 100644 index 0e340b87f..000000000 --- a/Week3/step2-6.js +++ /dev/null @@ -1,34 +0,0 @@ -'use strict'; - -const arr2d = [ - [1, 2], - [3, 4], - [5, 6] -]; -const arr3d = [ - [ - [1, 2], - [3, 4] - ], - [ - [5, 6], - [7, 8] - ] -]; - -function flattenArray2d(arr) { - return arr.flat(); -} - -function flattenArray3d(arr) { - return arr.flat(2); - -} -console.log(flattenArray2d(arr2d)); // -> [1, 2, 3, 4, 5, 6] -console.log(flattenArray3d(arr3d)); // -> [1, 2, 3, 4, 5, 6, 7, 8] - -// Do not change or remove anything below this line -module.exports = { - flattenArray2d, - flattenArray3d, -}; \ No newline at end of file From ce163b5dfaeea7b8482222ca9adfd6e270eacf4a Mon Sep 17 00:00:00 2001 From: Rahime YILDIZ <50872722+rcmzyldz@users.noreply.github.com> Date: Fri, 2 Aug 2019 02:15:00 +0200 Subject: [PATCH 22/26] Delete step2-5.js --- Week3/step2-5.js | 24 ------------------------ 1 file changed, 24 deletions(-) delete mode 100644 Week3/step2-5.js diff --git a/Week3/step2-5.js b/Week3/step2-5.js deleted file mode 100644 index 0961a30b0..000000000 --- a/Week3/step2-5.js +++ /dev/null @@ -1,24 +0,0 @@ -'use strict'; - -function multiplyAll(arr) { - // eslint-disable-next-line - let product = 1; - - for (var i = 0; i < arr.length; i++) { - for (var j = 0; j < arr[i].length; j++) { - product = product * arr[i][j]; - } - - return product; - } - - const result = multiplyAll([ - [1, 2], - [3, 4], - [5, 6] - ]); - console.log(result); // 720 - - // Do not change or remove anything below this line - module.exports = multiplyAll; -} \ No newline at end of file From af37649fdd121a0c2652ded2b93088bfd9edc2e6 Mon Sep 17 00:00:00 2001 From: Rahime YILDIZ <50872722+rcmzyldz@users.noreply.github.com> Date: Fri, 2 Aug 2019 02:15:09 +0200 Subject: [PATCH 23/26] Delete step2-4.js --- Week3/step2-4.js | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 Week3/step2-4.js diff --git a/Week3/step2-4.js b/Week3/step2-4.js deleted file mode 100644 index be4379e76..000000000 --- a/Week3/step2-4.js +++ /dev/null @@ -1,12 +0,0 @@ -'use strict'; - -function Dog() { - this.name = 'MoonLight'; - this.color = 'blonde'; - this.numLegs = 4; -} - -const hound = new Dog(); - -// Do not change or remove anything below this line -module.exports = hound; \ No newline at end of file From 49b6658c84aaba645b589812e076dbb449d8eb9b Mon Sep 17 00:00:00 2001 From: Rahime YILDIZ <50872722+rcmzyldz@users.noreply.github.com> Date: Fri, 2 Aug 2019 02:15:18 +0200 Subject: [PATCH 24/26] Delete step2-3.js --- Week3/step2-3.js | 52 ------------------------------------------------ 1 file changed, 52 deletions(-) delete mode 100644 Week3/step2-3.js diff --git a/Week3/step2-3.js b/Week3/step2-3.js deleted file mode 100644 index 7859a8292..000000000 --- a/Week3/step2-3.js +++ /dev/null @@ -1,52 +0,0 @@ -'use strict'; - -// Use a 'for' loop -function repeatStringNumTimesWithFor(str, num) { - // eslint-disable-next-line prefer-const - let result = ''; - - for (let i = num; i > 0; i--) { - result += str; - } - - return result; -} - -console.log('for', repeatStringNumTimesWithFor('abc', 3)); - -// Use a 'while' loop -function repeatStringNumTimesWithWhile(str, num) { - // eslint-disable-next-line prefer-const - let result = ''; - - while (num > 0) { - result += str; - num--; - } - - return result; -} - -console.log('while', repeatStringNumTimesWithWhile('abc', 3)); - -// Use a 'do...while' loop -function repeatStringNumTimesWithDoWhile(str, num) { - // eslint-disable-next-line prefer-const - let result = ''; - do { - result += str; - num--; - } while (num > 0); - - - return result; -} - -console.log('do-while', repeatStringNumTimesWithDoWhile('abc', 3)); - -// Do not change or remove anything below this line -module.exports = { - repeatStringNumTimesWithFor, - repeatStringNumTimesWithWhile, - repeatStringNumTimesWithDoWhile, -}; \ No newline at end of file From 366a1fec0623efb7db293cb3d23225a61351cd04 Mon Sep 17 00:00:00 2001 From: Rahime YILDIZ <50872722+rcmzyldz@users.noreply.github.com> Date: Fri, 2 Aug 2019 02:15:29 +0200 Subject: [PATCH 25/26] Delete step2-2.js --- Week3/step2-2.js | 37 ------------------------------------- 1 file changed, 37 deletions(-) delete mode 100644 Week3/step2-2.js diff --git a/Week3/step2-2.js b/Week3/step2-2.js deleted file mode 100644 index 8fcfba9ba..000000000 --- a/Week3/step2-2.js +++ /dev/null @@ -1,37 +0,0 @@ -'use strict'; - -function threeFive(startIndex, stopIndex, threeCallback, fiveCallback) { - const numbers = []; - for (let i = startIndex; i <= stopIndex; i++) { - numbers.push(i); - } - - numbers.map(x => { - if (x % 5 === 0 && x % 3 === 0) { - threeCallback(x); - fiveCallback(x) - } else if (x % 3 === 0) { - threeCallback(x) - } else if (x % 5 === 0) { - fiveCallback(x) - } - }) - - // Replace this comment and the next line with your code - console.log(startIndex, stopIndex, threeCallback, fiveCallback, numbers); -} - -function sayThree(number) { - - console.log(number + "is dividable by 3"); -} - -function sayFive(number) { - // Replace this comment and the next line with your code - console.log(number + "is dividable by 5"); -} - -threeFive(10, 15, sayThree, sayFive); - -// Do not change or remove anything below this line -module.exports = threeFive; \ No newline at end of file From 9331617a5c7aabf709f7a81b7f27616daabc4bb3 Mon Sep 17 00:00:00 2001 From: Rahime YILDIZ <50872722+rcmzyldz@users.noreply.github.com> Date: Fri, 2 Aug 2019 02:15:37 +0200 Subject: [PATCH 26/26] Delete step2-1.js --- Week3/step2-1.js | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 Week3/step2-1.js diff --git a/Week3/step2-1.js b/Week3/step2-1.js deleted file mode 100644 index 77717b20e..000000000 --- a/Week3/step2-1.js +++ /dev/null @@ -1,14 +0,0 @@ -'use strict'; - -function foo(func) { - return func(); -} - -function bar() { - console.log('Hello, I am bar!'); -} - -foo(bar); - -// Do not change or remove anything below this line -module.exports = foo; \ No newline at end of file