diff --git a/Week1/homework/app.js b/Week1/homework/app.js index a9b5f75d8..0cad1f9ce 100644 --- a/Week1/homework/app.js +++ b/Week1/homework/app.js @@ -1,11 +1,65 @@ -'use strict'; -{ - const bookTitles = [ - // Replace with your own book titles - 'harry_potter_chamber_secrets', - ]; +'use strict' +const books = [ + { + title :"Harry Potter Chamber of Secrets", + language:"english", + author:"Joanne K. Rowling", - // Replace with your own code - console.log(bookTitles); + }, + + { + title:"Alchemist", + language:"english", + author:"paulo-co", + + }, + + { + title:"Paula", + language:"english", + author:"isabel allende", + + }, + + { + + title:"Orlando", + language:"english", + author:"virginia-wolf", + + }, + + { + title:"Divine Comedy", + language:"English", + author:"dante", + + }, + + { + title:"The Odyssey", + language: "english", + author:"Homeros", + + }, + +] + +function createAndAppend(parent,typ,attributes={}) { + + const elem = document.createElement(typ) + + parent.appendChild(elem) + + for (const key in attributes) + + elem[key] = attributes[key] + return elem } + +const ul = createAndAppend(document.body, 'ul', {}) +for (const index in books) { + const book = books[index] + createAndAppend(ul, 'li', {value : index, innerHTML: book.title}) +} \ No newline at end of file diff --git a/Week1/homework/index.html b/Week1/homework/index.html index b22147cd1..93ea94ef0 100644 --- a/Week1/homework/index.html +++ b/Week1/homework/index.html @@ -1 +1,10 @@ - \ No newline at end of file + + + + Codestin Search App + + + + + + \ No newline at end of file diff --git a/Week1/homework/odyssy.jpg b/Week1/homework/odyssy.jpg new file mode 100644 index 000000000..f349be938 Binary files /dev/null and b/Week1/homework/odyssy.jpg differ diff --git a/Week1/homework/paula.jpg b/Week1/homework/paula.jpg new file mode 100644 index 000000000..6cab39571 Binary files /dev/null and b/Week1/homework/paula.jpg differ diff --git a/Week1/homework/potter.jpg b/Week1/homework/potter.jpg new file mode 100644 index 000000000..f98d221ed Binary files /dev/null and b/Week1/homework/potter.jpg differ diff --git a/Week1/homework/woolf.jpg b/Week1/homework/woolf.jpg new file mode 100644 index 000000000..8be454ab3 Binary files /dev/null and b/Week1/homework/woolf.jpg differ diff --git a/Week2/example.html b/Week2/example.html index 374f064c4..0d0d7e4eb 100644 --- a/Week2/example.html +++ b/Week2/example.html @@ -14,7 +14,8 @@

Here is your advice for the day:

-

+ + diff --git a/Week2/homework/map-filter.js b/Week2/homework/map-filter.js index c8e8a88c1..0346ce45e 100644 --- a/Week2/homework/map-filter.js +++ b/Week2/homework/map-filter.js @@ -1,4 +1,4 @@ -'use strict'; +/*'use strict'; function doubleOddNumbers(numbers) { // Replace this comment and the next line with your code @@ -12,4 +12,29 @@ console.log(doubleOddNumbers(myNumbers)); module.exports = { myNumbers, doubleOddNumbers, +}; */ + +'use strict'; + +function doubleOddNumbers(numbers) { + + numbers = numbers.filter(num => num % 2 === 1).map(num => num * 2); + + console.log(numbers); + + return numbers; + + + +const myNumbers = [1, 2, 3, 4]; + +console.log(doubleOddNumbers(myNumbers)); +module.exports = { + + myNumbers, + + doubleOddNumbers, + }; + +//finished \ No newline at end of file diff --git a/Week2/homework/week2maartjes-work.js b/Week2/homework/week2maartjes-work.js new file mode 100644 index 000000000..4fa673ab9 --- /dev/null +++ b/Week2/homework/week2maartjes-work.js @@ -0,0 +1,133 @@ + +'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) { + + const inHoursArr = tasks.map(task => task.duration / 60).filter(hours => hours <= 2); + + const maartjesPayArr = inHoursArr.map(hours => hours * maartjesHourlyRate); + + const totalPay = maartjesPayArr.reduce((sum, amount) => sum + amount); + + const toEuro = totalPay.toFixed(2); + + return toEuro; + +} + + + + + +const earnings = computeEarnings(maartjesTasks, maartjesHourlyRate); + + + +//converting + + + +console.log(`Martje has earned €${earnings}`); + + +module.exports = { + + maartjesTasks, + + maartjesHourlyRate, + + computeEarnings, + +}; \ No newline at end of file diff --git a/Week2/lecture-exercises.js b/Week2/lecture-exercises.js index 1fdfef4e0..68d136493 100644 --- a/Week2/lecture-exercises.js +++ b/Week2/lecture-exercises.js @@ -9,9 +9,41 @@ async function getRandomAdvice() { return adviceData.slip.advice; } +let allAdvice=[] +const adviceEl = document.getElementById('advice'); + + +function updateDOM() { + adviceEl.innerHTML= ''; + + allAdvice.forEach((advice, index)=> { + + + const adviceItem=document.createElement ('li') + adviceEl.appendChild(adviceItem); + adviceItem.innerText=advice; + + const removeButton =document.createElement('button') + removeButton.innerText='remove'; + adviceItem.appendChild(removeButton); + removeButton.addEventListener('click',() => deleteAdvice(index));_ +}) + } + function deleteAdvice (index){ + allAdvice.splice(index,1); + updateDOM(); + } + function upcaseAllAdvice (){ + allAdvice=allAdvice.map(advice => advice.toUpperCase()); + updateDOM(); + async function setRandomAdvice() { - const adviceEl = document.getElementById('advice'); - adviceEl.innerText = await getRandomAdvice(); + allAdvice.push (await getRandomAdvice()); + updateDOM(); } setRandomAdvice(); + +document.getElementById('add-advice').addEventListener('click', setRandomAdvice); + +document.getElementById('upcase-everything').addEventListener('click', upcaseAllAdvice); \ No newline at end of file diff --git a/Week3/homework/step2-1.js b/Week3/homework/step2-1.js index d5699882c..1be9692e4 100644 --- a/Week3/homework/step2-1.js +++ b/Week3/homework/step2-1.js @@ -1,16 +1,11 @@ 'use strict'; - function foo(func) { - // What to do here? - // Replace this comment and the next line with your code - console.log(func); + func(); } - function bar() { console.log('Hello, I am bar!'); } - foo(bar); - -// Do not change or remove anything below this line module.exports = foo; + +//finished diff --git a/Week3/homework/step2-2.js b/Week3/homework/step2-2.js index dcd135040..a6f011250 100644 --- a/Week3/homework/step2-2.js +++ b/Week3/homework/step2-2.js @@ -1,23 +1,43 @@ 'use strict'; -function threeFive(startIndex, stopIndex, threeCallback, fiveCallback) { +{ + function threeFive(startIndex, stopIndex, threeCallback, fiveCallback) { + const numbers = []; + for (let i = startIndex; i <= stopIndex; i++) { - // Replace this comment and the next line with your code - console.log(startIndex, stopIndex, threeCallback, fiveCallback, numbers); -} + numbers.push(i); + + //A callback to call if the number is divisible by 3 + + if (i % 3 === 0) { + + threeCallback(i); + + } + + //A callback by 5 + + if (i % 5 === 0) { + + fiveCallback(i); + + }}} + + +threeFive() function sayThree(number) { - // Replace this comment and the next line with your code - console.log(number); + console.log(number, 'value is divisible by 3'); } + + function sayFive(number) { - // Replace this comment and the next line with your code - console.log(number); + console.log(number, 'value is divisible by 5'); } - threeFive(10, 15, sayThree, sayFive); - -// Do not change or remove anything below this line module.exports = threeFive; + +} +//finished \ No newline at end of file diff --git a/Week3/homework/step2-3.js b/Week3/homework/step2-3.js index 00845c5eb..a0eaf9b7f 100644 --- a/Week3/homework/step2-3.js +++ b/Week3/homework/step2-3.js @@ -1,45 +1,38 @@ 'use strict'; -// Use a 'for' loop function repeatStringNumTimesWithFor(str, num) { - // 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 = 0; i < num; i++) { + result += str; + } return result; } -console.log('for', repeatStringNumTimesWithFor('abc', 3)); +console.log('for', repeatStringNumTimesWithFor('abc', 3)) -// Use a 'while' loop +//while loop function repeatStringNumTimesWithWhile(str, num) { - // eslint-disable-next-line prefer-const - let result = ''; - - // Replace this comment and the next line with your code - console.log(str, num, result); - + let result = '' + let counter = 0; + while (counter < num) { + result += str; + counter++; + } 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 = ''; - - // Replace this comment and the next line with your code - console.log(str, num, result); - + let i = 0; + if (num > 0) { + do { + result += str; + i++; + } while (i < num); + } return result; } - -console.log('do-while', repeatStringNumTimesWithDoWhile('abc', 3)); - -// Do not change or remove anything below this line +console.log('do-while', repeatStringNumTimesWithDoWhile('abc', 0)); module.exports = { repeatStringNumTimesWithFor, repeatStringNumTimesWithWhile, diff --git a/Week3/homework/step2-4.js b/Week3/homework/step2-4.js index b11b1dcb6..0221a30d6 100644 --- a/Week3/homework/step2-4.js +++ b/Week3/homework/step2-4.js @@ -1,10 +1,9 @@ 'use strict'; - function Dog() { - // add your code here + this.name = 'ginger'; + this.color = 'white'; + this.numLegs = 4; } - const hound = new Dog(); - -// Do not change or remove anything below this line module.exports = hound; +//finished diff --git a/Week3/homework/step2-5.js b/Week3/homework/step2-5.js index cbb54fa1d..0932ad91f 100644 --- a/Week3/homework/step2-5.js +++ b/Week3/homework/step2-5.js @@ -1,17 +1,10 @@ 'use strict'; - -function multiplyAll(arr) { - // eslint-disable-next-line - let product = 1; - - // Replace this comment and the next line with your code - console.log(arr, product); - - 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; + function multiplyAll(arr) { + let product = 1; + console.log(arr, product); + return product; + } + const result = multiplyAll([[2, 4], [6, 8], [10, 12]]); + console.log(result); // 46.080 + module.exports = multiplyAll; +//finished diff --git a/Week3/homework/step2-6.js b/Week3/homework/step2-6.js index ffe95b9f7..d3ea9eff1 100644 --- a/Week3/homework/step2-6.js +++ b/Week3/homework/step2-6.js @@ -1,22 +1,25 @@ 'use strict'; - -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); + const arr3d = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]; + function flattenArray2d(arr) { + let flattenArr2 = []; + for (let i = 0; i < arr.length; i++) { + for (let j = 0; j < arr[i].length; j++) { + flattenArr2.push(arr[i][j]); + } + } + return flattenArray2d; } - function flattenArray3d(arr) { - // Replace this comment and the next line with your code - console.log(arr); +const flattenArr3 = []; +for (let i = 0; i < arr.length; i++) { +for (let j = 0; j < arr[i].length; j++) { +for (let l = 0; l < arr[i][j].length; l++) { +flattenArr3.push(arr[i][j][l]); + } + } + } + return flattenArray3d; } - -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,