diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 000000000..f9fc04562 Binary files /dev/null and b/.DS_Store differ diff --git a/Week1/.DS_Store b/Week1/.DS_Store new file mode 100644 index 000000000..95e0f3e27 Binary files /dev/null and b/Week1/.DS_Store differ diff --git a/Week1/homework/app.js b/Week1/homework/app.js index ffef836dc..c294ac8d1 100644 --- a/Week1/homework/app.js +++ b/Week1/homework/app.js @@ -1,11 +1,163 @@ -'use strict'; -{ - const bookTitles = [ - // Replace with your own book titles - 'harry_potter_chamber_secrets' - ]; +let myFavoritBooks = +["the_alchemist",//Paulo Coelho +"forty_rules_of_love",//Elif Shafak +"journey_to_a_better_you",//Joel Osteen +"eat_that_frog",//Brian Tracy +"by_the_river_piedra_i_sat_down_and_wept",//Paulo Coelho +"the_power_of_i_am",//Joel Osteen +"the_secret",//Rhonda Byrne +"one_hundred_years_of_solitude",//Gabriel Garcia Marquez +"the_right_questiones",//Debbie Ford +"someone_i_loved"//Anna Gavalda +]; - // Replace with your own code - console.log(bookTitles); +// console.log(myFavoritBooks); + + +//write books id on HTML from an array +function createUl(arr){ + let ul = document.createElement('ul'); + ul.setAttribute('id', 'myFavoritBooks'); + document.body.appendChild(ul) + for (let i=0; i \ No newline at end of file + + + + Books list + + + +

JavaScript Week3 - DOM

+ Link to assignment source +
+
+
+
+
+ + + + \ No newline at end of file diff --git a/Week1/homework/main.css b/Week1/homework/main.css new file mode 100644 index 000000000..14874fe22 --- /dev/null +++ b/Week1/homework/main.css @@ -0,0 +1,44 @@ +html{ + background-color:lightblue; + background-image: url(https://pre00.deviantart.net/c69b/th/pre/i/2010/071/b/2/bookcase_by_jcallius.jpg); + margin: 2px; + box-sizing:border-box; + display: block; +} +ul{ +background-color: beige; +padding: 30px 40px 40px 40px; +margin-right: 500px; +margin-left: 10px; +list-style-type: none; +} +a{ + background-color: beige; + color:black; + text-align-last: center; + padding: 10px 10px 10px 10px; + margin: 40px 10px 10px 10px; +} +h1{ + color: darkred; + background-color: beige; + margin:50px 50px 50px 50px; + text-align-last: center; + font-size: 30px; + font-family: fantasy; +} + +h2 { + font-family: Tahoma, sans-serif; + font-size: 16px; + color:white; + background-color: orangered; + margin:0px 400px 20px 10px; +} + +img { + width: 300px; + height: 350px; + border: 3px solid darkred; +} + diff --git a/Week1/homework/style.css b/Week1/homework/style.css deleted file mode 100644 index bab13ec23..000000000 --- a/Week1/homework/style.css +++ /dev/null @@ -1 +0,0 @@ -/* add your styling here */ \ No newline at end of file diff --git a/Week2/.DS_Store b/Week2/.DS_Store new file mode 100644 index 000000000..5652b29ed Binary files /dev/null and b/Week2/.DS_Store differ diff --git a/Week2/homework/maartjes_work.js b/Week2/homework/maartjes_work.js index 0b451d122..eebd3a000 100644 --- a/Week2/homework/maartjes_work.js +++ b/Week2/homework/maartjes_work.js @@ -45,3 +45,19 @@ const tuesday = [ const tasks = monday.concat(tuesday); // Add your code here + +// change MIN to HOUR + + let changedDuration = tasks.map( tasks => tasks.duration /= 60); + console.log(changedDuration); + +// Filter out everything that took less than two hours + +let filterDuration = changedDuration.filter( changedDuration => changedDuration >= 2); +console.log (filterDuration); + +// Multiply the each duration by a per-hour rate for billing and sum it all up. + +let financial = changedDuration.map(changedDuration => changedDuration *= 30).reduce((total, amount) => total += amount); +console.log(" Maartje should earn " + financial + "€"); + diff --git a/Week2/homework/map_filter.js b/Week2/homework/map_filter.js index b6af22631..8e0d95ba5 100644 --- a/Week2/homework/map_filter.js +++ b/Week2/homework/map_filter.js @@ -3,3 +3,16 @@ const numbers = [1, 2, 3, 4]; // Add your code here +const numbers = [1, 2, 3, 4]; + +const odd = numbers.filter(i => i % 2 !== 0); + +const newNumbers = odd.map(i => { + if (odd===false) { + return i; + } else { + return i * 2;} +}); + + +console.log('The doubled numbers are', newNumbers); // ==> [2, 6] \ No newline at end of file diff --git a/Week3/homework/1-step3.js b/Week3/homework/1-step3.js index bee3be0a0..ba03e729b 100644 --- a/Week3/homework/1-step3.js +++ b/Week3/homework/1-step3.js @@ -1,11 +1,13 @@ 'use strict'; - + +// step 3 => 1 function foo(func) { - // What to do here? -} - -function bar() { - console.log('Hello, I am bar!'); -} + func(); + } + + function bar() { + console.log('Hello, I am bar!'); + } + + foo(bar); -foo(bar); diff --git a/Week3/homework/2-step3.js b/Week3/homework/2-step3.js index 777ca2038..2c73debc8 100644 --- a/Week3/homework/2-step3.js +++ b/Week3/homework/2-step3.js @@ -1,8 +1,43 @@ -'use strict'; -function threeFive(startIndex, stopIndex, threeCallback, fiveCallback) { - const values = []; - // Add your code here -} +// step 3 => 2 -threeFive(10, 15, sayThree, sayFive); + function threeFive(startIndex, stopIndex, threeCallback, fiveCallback) { + const values = []; + for (var i = startIndex; i <= stopIndex; i++) { + values.push(i); + } + + values.forEach(function (x) { + + + if ((x % 5 === 0) && (x % 3 === 0)) { + console.log("value = " + x) + fiveCallback() + threeCallback(); + } + else if (x % 3 === 0) { + console.log("value = " + x); + threeCallback(); + } + else if (x % 5 === 0) { + console.log("value = " + x); + fiveCallback(); + } + + + }); + } + + + let sayThree = function(threeCallback) { + console.log("3"); + + }; + + let sayFive = function(fiveCallback) { + console.log("5"); + + }; + + + threeFive(10, 15, sayThree, sayFive) diff --git a/Week3/homework/3-step3.js b/Week3/homework/3-step3.js index 75200818b..201fd523e 100644 --- a/Week3/homework/3-step3.js +++ b/Week3/homework/3-step3.js @@ -1,25 +1,51 @@ -'use strict'; -// use a 'for' loop + // step 3 => 3 + + + // FOR loop function repeatStringNumTimesWithFor(str, num) { - // add your code here - return str; -} + let x = ''; + if (num < 0) { + return x; + } + else { + for (let i = 0; i < num; i++) { + x += str + } + } + return x; + } + + console.log('for', repeatStringNumTimesWithFor('abc', 3)); -console.log('for', repeatStringNumTimesWithFor('abc', 3)); -// use a 'while' loop +// WHILE loop function repeatStringNumTimesWithWhile(str, num) { - // add your code here - return str; + let x = ''; + while (num > 0) { + x += str; + num--; + } + return x; } console.log('while', repeatStringNumTimesWithWhile('abc', 3)); -// use a 'do...while' loop -function repeatStringNumTimesWithDoWhile(str, num) { - // add your code here - return str; + +// DO....WHILE loop +function repeatStringNumTimesWithWhile(str, num) { + let x = ''; + + do { + x += str; + num--; + + } while (num > 0); + + return x; } + + console.log(' do...while', repeatStringNumTimesWithWhile('abc', 3)); + + -console.log('while', repeatStringNumTimesWithDoWhile('abc', 3)); diff --git a/Week3/homework/4-step3.js b/Week3/homework/4-step3.js index 52a0e9d74..a6b5d1f6d 100644 --- a/Week3/homework/4-step3.js +++ b/Week3/homework/4-step3.js @@ -1,2 +1,12 @@ -'use strict'; -// paste your freeCodeCamp solutions in here + // step 3 => 4 + + + function DOG() { + this.name = "Fidel"; + this.color = "white"; + this.numLegs = 4; + } + + let pet = new DOG(); + pet.name = "Misha"; + console.log(pet); diff --git a/Week3/homework/5-step3.js b/Week3/homework/5-step3.js index 52a0e9d74..125547404 100644 --- a/Week3/homework/5-step3.js +++ b/Week3/homework/5-step3.js @@ -1,2 +1,17 @@ -'use strict'; -// paste your freeCodeCamp solutions in here + +// step 3 => 5 + + +function multiplyAll(arr) { + var product = 1; + + for (var i=0; i < arr.length; i++) { + for (var j=0; j < arr[i].length; j++) { + console.log(product*arr[i][j]); + } + } + + return product; + } + + multiplyAll([[1,2],[3,4],[5,6,7]]); \ No newline at end of file diff --git a/Week3/homework/6-step3.js b/Week3/homework/6-step3.js index 89076b078..ac97f202c 100644 --- a/Week3/homework/6-step3.js +++ b/Week3/homework/6-step3.js @@ -1,6 +1,21 @@ -'use strict'; + +// step 3 => 6 + const arr2d = [[1, 2], [3, 4], [5, 6]]; const arr3d = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]; -// add your solution here, or add a comment on how you would tackle this problem +for (let i = 0; i < arr2d.length; i++) { + for (let j = 0; j < arr2d[i].length; j++) { + console.log(arr2d[i][j]); + } + } + + for (let i = 0; i < arr3d.length; i++) { + for (let j = 0; j < arr3d[i].length; j++){ + for (let x = 0; x < arr3d[i].length; x++){ + + console.log(arr3d[i][j][x]); + } + } +} diff --git a/Week3/homework/7-step3.js b/Week3/homework/7-step3.js index af1712faf..b4166dbb6 100644 --- a/Week3/homework/7-step3.js +++ b/Week3/homework/7-step3.js @@ -1,25 +1,26 @@ -'use strict'; + +// step 3 => 7 + const x = 9; function f1(val) { val = val + 1; return val; } +f1(x); +console.log(x); //9 -f1(x); - -console.log(x); - +/*the f1 function receive a variable as an input parameter and it passes the variable by value. +It means that the variable will be only changed inside the fucntion and never affect the outside.*/ const y = { x: 9 }; function f2(val) { val.x = val.x + 1; return val; } - f2(y); +console.log(y); //10 -console.log(y); - -// Add your explanation as a comment here - +/* the f2 function receive an object as an input parameter and it passes the variable by reference +It means that the varibale will be changed both inside and outside in the second fucntion . + */ diff --git a/Week3/homework/step4-bonus.js b/Week3/homework/step4-bonus.js index 4e89b29e7..115b7f315 100644 --- a/Week3/homework/step4-bonus.js +++ b/Week3/homework/step4-bonus.js @@ -1,10 +1,33 @@ -'use strict'; -const values = ['a', 'b', 'c', 'd', 'a', 'e', 'f', 'c']; +// step 4 => Bonus -// Add your function here. Try and come up with a good name for this function +const letters = ['a', 'b', 'c', 'd', 'a', 'e', 'f', 'c']; +const numbers = [1, 2, 3, 4, 1, 5, 6, 3]; + + +// SET soloution +function getUnique_set(arr){ + return [... new Set(arr)]; +} + + +//forEach solution +function getUnique_forEach(arr){ + let uniqeArray = []; + arr.forEach(element => { + if(!uniqeArray.includes(element)){ + uniqeArray.push(element); + } + }); + return uniqeArray; +} + +getUnique_set(letters); +getUnique_set(numbers); + + +getUnique_forEach(letters); +getUnique_forEach(numbers); +} -// Replace `yourFunction` with the name of the function you just created -const uniqueValues = yourFunction(values); -console.log(uniqueValues); diff --git a/Week3/homework/step4.js b/Week3/homework/step4.js index e38d43447..616fc5ef0 100644 --- a/Week3/homework/step4.js +++ b/Week3/homework/step4.js @@ -2,7 +2,17 @@ // Add your code here -const addSix = createBase(6); + // step 4 + + function createBase(base) { + const innerFunction = function (number) { + return base + number; + }; + + return innerFunction; + } + +let addSix = createBase(6); +console.log(addSix(10)); +console.log(addSix(21)); -addSix(10); // returns 16 -addSix(21); // returns 27