diff --git a/Week1/homework/app.js b/Week1/homework/app.js index a9b5f75d8..30ba13966 100644 --- a/Week1/homework/app.js +++ b/Week1/homework/app.js @@ -1,11 +1,184 @@ 'use strict'; +{ + let games = [ + { + title: 'stardew_valley', + year: '2016', + company: 'ConcernedApe', + type: 'role play', + image: 'images/stardewvalley.jpg' + }, + { + title: 'overwatch', + year: '2016', + company: 'blizzard', + type: 'shooter', + image: 'images/overwatch.png' + }, + { + title: 'lineage', + year: '2003', + company: 'NCSOFT', + type: 'MMORPG', + image: 'images/lineage.png' + }, + { + title: 'counter_strike', + year: '2000', + company: 'namco', + type: 'shooter', + image: 'images/counterstrike.jpg' + }, + { + title: 'wow', + year: '2004', + company: "blizzard", + type: 'role play', + image: 'images/wow.jpg' + }, + { + title: 'house_of_the_dead', + year: '1996', + company: 'sega', + type: 'light gun shooter', + image: 'images/hotd.jpg' + } + ] + + document.body.onload = listGames; + + function listGames() { + let ul = document.createElement('ul') + for (const game of games) { + let li = document.createElement('li'); + li.innerHTML = `

${game.title}

` + li.innerHTML += `Year: ${game.year}
` + li.innerHTML += `Type: ${game.type}
` + li.innerHTML += `Company: ${game.company}
` + let cover = document.createElement("img"); + cover.width = 250 + cover.src = game.image; + li.appendChild(cover) + ul.appendChild(li); + } + document.body.appendChild(ul); + } +} +/* 'use strict'; + +document.body.style.backgroundColor = "#AA0054"; + { - const bookTitles = [ - // Replace with your own book titles - 'harry_potter_chamber_secrets', - ]; + const gameTitles = [ + 'stardew_valley', + 'overwatch', + 'lineage', + 'counter_strike', + 'wow', + 'house_of_the_dead' + ]; + + let objGames = { + 'stardew_valley': { + properties: { + year: '2016', + company: 'ConcernedApe', + type: 'role play', + image: 'stardewvalley.jpg' + }, + }, + 'overwatch': { + properties: { + year: '2016', + company: 'blizzard', + type: 'shooter', + image: 'overwatch.png' + }, + }, + 'lineage': { + properties: { + year: '2003', + company: 'NCSOFT', + type: 'MMORPG', + image: 'lineage.png' + }, + }, + 'counter_strike': { + properties: { + year: '2000', + company: 'namco', + type: 'shooter', + image: 'counterstrike.jpg' + }, + }, + 'wow': { + properties: { + year: '2004', + company: "blizzard", + type: 'role play', + image: 'wow.jpg' + }, + }, + 'house_of_the_dead': { + properties: { + year: '1996', + company: 'sega', + type: 'light gun shooter', + image: 'hotd.jpg' + } + } + } + + + + function listGamesOld() { + + + let ul = document.createElement('ul') + for (let i = 0; i < gameTitles.length; i++) { + let li = document.createElement('li'); + li.textContent = gameTitles[i]; + console.log() + ul.appendChild(li); + + } + + document.body.appendChild(ul); + + } + document.body.onload = listGames; + + + + + function listGames() { + + let i = 0; + let ul = document.createElement('ul') + let gameTitles = Object.keys(objGames); + let numberOfGames = gameTitles.length; + for (i = 0; i < numberOfGames; i++) { + console.log(gameTitles[i]); + console.log(objGames[gameTitles[i]]); + let li = document.createElement('li'); + li.innerHTML = `

${gameTitles[i]}

` + li.innerHTML += `
  • Year: ${objGames[gameTitles[i]].properties.year}
  • ` + li.innerHTML += `
  • Type: ${objGames[gameTitles[i]].properties.type}
  • ` + li.innerHTML += `
  • Company: ${objGames[gameTitles[i]].properties.company}
  • ` + let cover = document.createElement("img"); + cover.src = objGames[gameTitles[i]].image; + li.innerHTML += ` ${document.getElementById("albumCovers").appendChild(cover)}`; + + + ul.appendChild(li); + + } + + document.body.appendChild(ul); + + } - // Replace with your own code - console.log(bookTitles); } + */ + diff --git a/Week1/homework/images/counterstrike.jpg b/Week1/homework/images/counterstrike.jpg new file mode 100644 index 000000000..48440f953 Binary files /dev/null and b/Week1/homework/images/counterstrike.jpg differ diff --git a/Week1/homework/images/hotd.jpg b/Week1/homework/images/hotd.jpg new file mode 100644 index 000000000..6ecf8cc62 Binary files /dev/null and b/Week1/homework/images/hotd.jpg differ diff --git a/Week1/homework/images/lineage.png b/Week1/homework/images/lineage.png new file mode 100644 index 000000000..f8c4943c9 Binary files /dev/null and b/Week1/homework/images/lineage.png differ diff --git a/Week1/homework/images/overwatch.png b/Week1/homework/images/overwatch.png new file mode 100644 index 000000000..51387d528 Binary files /dev/null and b/Week1/homework/images/overwatch.png differ diff --git a/Week1/homework/images/stardewvalley.jpg b/Week1/homework/images/stardewvalley.jpg new file mode 100644 index 000000000..c898408f0 Binary files /dev/null and b/Week1/homework/images/stardewvalley.jpg differ diff --git a/Week1/homework/images/wow.jpg b/Week1/homework/images/wow.jpg new file mode 100644 index 000000000..d407b73f4 Binary files /dev/null and b/Week1/homework/images/wow.jpg differ diff --git a/Week1/homework/index.html b/Week1/homework/index.html index b22147cd1..51280cb86 100644 --- a/Week1/homework/index.html +++ b/Week1/homework/index.html @@ -1 +1,19 @@ - \ No newline at end of file + + + + + + + Javascript 2 + + + +
    Games I like to play
    +
    + +
    + + + \ No newline at end of file diff --git a/Week1/homework/style.css b/Week1/homework/style.css index bab13ec23..f30aa52e7 100644 --- a/Week1/homework/style.css +++ b/Week1/homework/style.css @@ -1 +1,41 @@ -/* add your styling here */ \ No newline at end of file +/* add your styling here */ + +html { + background: rgb(172, 108, 73); + background: linear-gradient(0deg, rgba(172, 108, 73, 1) 0%, rgba(233, 176, 54, 1) 100%); +} + +h2 { + color: rgb(5, 58, 58); + text-transform: uppercase; + text-decoration: underline; + font-family: sans-serif; +} + +ul { + display: flex; + flex-direction: row; + margin-left: 25%; + padding: 5%; + flex-wrap: wrap; + list-style-type: none; +} + +li { + align-content: center; + width: 50%; + flex-grow: 1; + font-family: sans-serif; + color: rgb(5, 58, 58); +} + +img { + margin: 2%; +} + +#main { + font-family: sans-serif; + text-align: center; + font-size: 3em; + color: rgb(5, 58, 58); +} \ No newline at end of file diff --git a/Week2/example.html b/Week2/example.html index 374f064c4..72c0fe92f 100644 --- a/Week2/example.html +++ b/Week2/example.html @@ -1,20 +1,25 @@ - - - Sample exercise - - - -

    Here is your advice for the day:

    -

    - - - + + + + Sample exercise + + + + +

    Here is your advice for the day:

    + + + + + + \ No newline at end of file diff --git a/Week2/homework/maartjes-work.js b/Week2/homework/maartjes-work.js index 49772eb44..588b80a1b 100644 --- a/Week2/homework/maartjes-work.js +++ b/Week2/homework/maartjes-work.js @@ -1,65 +1,68 @@ '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, - }, + { + 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, - }, + { + 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 - console.log(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; } -// eslint-disable-next-line no-unused-vars +// 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 €${'replace this string with the earnings rounded to euro cents'}`); +console.log(`Maartje has earned €${earnings}`); // Do not change or remove anything below this line module.exports = { - maartjesTasks, - maartjesHourlyRate, - computeEarnings, + maartjesTasks, + maartjesHourlyRate, + computeEarnings, }; diff --git a/Week2/homework/map-filter.js b/Week2/homework/map-filter.js index c8e8a88c1..384047064 100644 --- a/Week2/homework/map-filter.js +++ b/Week2/homework/map-filter.js @@ -1,6 +1,6 @@ 'use strict'; -function doubleOddNumbers(numbers) { +/* function doubleOddNumbers(numbers) { // Replace this comment and the next line with your code console.log(numbers); } @@ -12,4 +12,20 @@ console.log(doubleOddNumbers(myNumbers)); module.exports = { myNumbers, doubleOddNumbers, -}; +}; */ + + +function doubleOddNumbers(numbers) { + const oddNumbers = numbers.filter(num => num % 2 !== 0); + const doubleNumbers = oddNumbers.map(num => num * 2); + return doubleNumbers; +} + +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 diff --git a/Week2/homework/squirtle-sprites.css b/Week2/homework/squirtle-sprites.css new file mode 100644 index 000000000..a5e754637 --- /dev/null +++ b/Week2/homework/squirtle-sprites.css @@ -0,0 +1,7 @@ +html { + background-color: blanchedalmond; +} + +img { + width: 250px; +} \ No newline at end of file diff --git a/Week2/homework/squirtle-sprites.html b/Week2/homework/squirtle-sprites.html new file mode 100644 index 000000000..b14348902 --- /dev/null +++ b/Week2/homework/squirtle-sprites.html @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Week2/homework/squirtle-sprites.js b/Week2/homework/squirtle-sprites.js index b6b6e2920..b6f8dbad3 100644 --- a/Week2/homework/squirtle-sprites.js +++ b/Week2/homework/squirtle-sprites.js @@ -5,7 +5,18 @@ (simulates calling a server to retrieve data) */ function fetchPokemonData() { - return '{"abilities":[{"ability":{"name":"rain-dish","url":"https://pokeapi.co/api/v2/ability/44/"},"is_hidden":true,"slot":3},{"ability":{"name":"torrent","url":"https://pokeapi.co/api/v2/ability/67/"},"is_hidden":false,"slot":1}],"base_experience":63,"forms":[{"name":"squirtle","url":"https://pokeapi.co/api/v2/pokemon-form/7/"}],"height":5,"held_items":[],"id":7,"is_default":true,"location_area_encounters":"https://pokeapi.co/api/v2/pokemon/7/encounters","name":"squirtle","order":10,"species":{"name":"squirtle","url":"https://pokeapi.co/api/v2/pokemon-species/7/"},"sprites":{"back_default":"https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/back/7.png","back_female":null,"back_shiny":"https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/back/shiny/7.png","back_shiny_female":null,"front_default":"https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/7.png","front_female":null,"front_shiny":"https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/shiny/7.png","front_shiny_female":null},"stats":[{"base_stat":43,"effort":0,"stat":{"name":"speed","url":"https://pokeapi.co/api/v2/stat/6/"}},{"base_stat":64,"effort":0,"stat":{"name":"special-defense","url":"https://pokeapi.co/api/v2/stat/5/"}},{"base_stat":50,"effort":0,"stat":{"name":"special-attack","url":"https://pokeapi.co/api/v2/stat/4/"}},{"base_stat":65,"effort":1,"stat":{"name":"defense","url":"https://pokeapi.co/api/v2/stat/3/"}},{"base_stat":48,"effort":0,"stat":{"name":"attack","url":"https://pokeapi.co/api/v2/stat/2/"}},{"base_stat":44,"effort":0,"stat":{"name":"hp","url":"https://pokeapi.co/api/v2/stat/1/"}}],"types":[{"slot":1,"type":{"name":"water","url":"https://pokeapi.co/api/v2/type/11/"}}],"weight":90}'; -} + const pokeInfo = + '{"abilities":[{"ability":{"name":"rain-dish","url":"https://pokeapi.co/api/v2/ability/44/"},"is_hidden":true,"slot":3},{"ability":{"name":"torrent","url":"https://pokeapi.co/api/v2/ability/67/"},"is_hidden":false,"slot":1}],"base_experience":63,"forms":[{"name":"squirtle","url":"https://pokeapi.co/api/v2/pokemon-form/7/"}],"height":5,"held_items":[],"id":7,"is_default":true,"location_area_encounters":"https://pokeapi.co/api/v2/pokemon/7/encounters","name":"squirtle","order":10,"species":{"name":"squirtle","url":"https://pokeapi.co/api/v2/pokemon-species/7/"},"sprites":{"back_default":"https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/back/7.png","back_female":null,"back_shiny":"https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/back/shiny/7.png","back_shiny_female":null,"front_default":"https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/7.png","front_female":null,"front_shiny":"https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/shiny/7.png","front_shiny_female":null},"stats":[{"base_stat":43,"effort":0,"stat":{"name":"speed","url":"https://pokeapi.co/api/v2/stat/6/"}},{"base_stat":64,"effort":0,"stat":{"name":"special-defense","url":"https://pokeapi.co/api/v2/stat/5/"}},{"base_stat":50,"effort":0,"stat":{"name":"special-attack","url":"https://pokeapi.co/api/v2/stat/4/"}},{"base_stat":65,"effort":1,"stat":{"name":"defense","url":"https://pokeapi.co/api/v2/stat/3/"}},{"base_stat":48,"effort":0,"stat":{"name":"attack","url":"https://pokeapi.co/api/v2/stat/2/"}},{"base_stat":44,"effort":0,"stat":{"name":"hp","url":"https://pokeapi.co/api/v2/stat/1/"}}],"types":[{"slot":1,"type":{"name":"water","url":"https://pokeapi.co/api/v2/type/11/"}}],"weight":90}'; + -/* Code goes below */ + /* Code goes below */ + + const pokeJSON = JSON.parse(pokeInfo); + console.log(pokeJSON); + for (const i in pokeJSON.sprites) { + const pokeImg = document.createElement('img'); + pokeImg.src = pokeJSON.sprites[i]; + document.body.appendChild(pokeImg); + } +} +fetchPokemonData(); diff --git a/Week2/homework/wesBrosArray.js b/Week2/homework/wesBrosArray.js new file mode 100644 index 000000000..42431ecf5 --- /dev/null +++ b/Week2/homework/wesBrosArray.js @@ -0,0 +1,2 @@ +//Array.prototype.filter() +//1. Filter the list of inventors for those who were born in the 1500's \ No newline at end of file diff --git a/Week2/lecture-exercises.js b/Week2/lecture-exercises.js index 1fdfef4e0..d0aad2169 100644 --- a/Week2/lecture-exercises.js +++ b/Week2/lecture-exercises.js @@ -1,17 +1,42 @@ async function getRandomAdvice() { - const adviceReq = fetch('https://api.adviceslip.com/advice'); // send request - const adviceResponse = await adviceReq; // wait until something comes back - // const jsonString = await adviceResponse.text(); - // return jsonString - // const adviceData = JSON.parse(jsonString) - // return jsonString - const adviceData = await adviceResponse.json(); // parses JSON string into native JavaScript object - return adviceData.slip.advice; + const adviceReq = fetch('https://api.adviceslip.com/advice'); // send request + const adviceResponse = await adviceReq; // wait until something comes back + // const jsonString = await adviceResponse.text(); + // return jsonString + // const adviceData = JSON.parse(jsonString) + // return jsonString + const adviceData = await adviceResponse.json(); // parses JSON string into native JavaScript object + return adviceData.slip.advice; +} +let allAdvice = []; +const adviceEl = document.getElementById('advice') + +function updateDOM() { + adviceEl.innerHTML = ''; + + allAdvice.forEach(advice => { + const adviceItem = document.createElement('li') + adviceEl.appendChild(adviceItem); + adviceItem.innerText = advice; + + const removeButton = document.createElement('button'); + removeButton.innerText = 'Remove'; + adviceItem.appenChild(removeButton); + + removeButton.addEventListener('click', () => deleteAdvice(index)); + }) +} +function deleteAdvice(index) { + allAdvice.splice(index, 1); + 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); \ No newline at end of file diff --git a/Week3/homework/step2-1.js b/Week3/homework/step2-1.js index d5699882c..d0574da1a 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); diff --git a/Week3/homework/step2-2.js b/Week3/homework/step2-2.js index dcd135040..65261478e 100644 --- a/Week3/homework/step2-2.js +++ b/Week3/homework/step2-2.js @@ -1,20 +1,30 @@ 'use strict'; function threeFive(startIndex, stopIndex, threeCallback, fiveCallback) { - const numbers = []; + const numbers = []; - // Replace this comment and the next line with your code - console.log(startIndex, stopIndex, threeCallback, fiveCallback, numbers); + for (let i = startIndex; i <= stopIndex; i++) { + numbers.push(i); + + if (i % 3 === 0) { + threeCallback(numbers); + } if (i % 5 === 0) { + fiveCallback(numbers); + } if (i % 3 === 0 && i % 5 === 0) { + threeCallback(numbers); + fiveCallback(numbers); + } + } } function sayThree(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(`This ${number} is divisible 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(`This ${number} is divisible by 5`); } threeFive(10, 15, sayThree, sayFive); diff --git a/Week3/homework/step2-3.js b/Week3/homework/step2-3.js index 00845c5eb..32bce2a98 100644 --- a/Week3/homework/step2-3.js +++ b/Week3/homework/step2-3.js @@ -2,46 +2,44 @@ // 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); - - return result; + let result = " "; + for (let i = 0; num > i; 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 = ''; - - // Replace this comment and the next line with your code - console.log(str, num, result); - - return result; + 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 = ''; - - // Replace this comment and the next line with your code - console.log(str, num, result); + let result = ''; + do { + result += str; + num--; + } while (num > 0); - 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, }; diff --git a/Week3/homework/step2-4.js b/Week3/homework/step2-4.js index b11b1dcb6..55421ae23 100644 --- a/Week3/homework/step2-4.js +++ b/Week3/homework/step2-4.js @@ -1,7 +1,10 @@ 'use strict'; +//constructor function Dog() { - // add your code here + this.name = "Bobby"; + this.color = "Black"; + this.numLegs = 4; } const hound = new Dog(); diff --git a/Week3/homework/step2-5.js b/Week3/homework/step2-5.js index cbb54fa1d..4dd96c73e 100644 --- a/Week3/homework/step2-5.js +++ b/Week3/homework/step2-5.js @@ -1,13 +1,14 @@ -'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); + let product = 1; + + for (let i = 0; i < arr.length; i++) { + for (let 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]]); diff --git a/Week3/homework/step2-6.js b/Week3/homework/step2-6.js index ffe95b9f7..037c1453e 100644 --- a/Week3/homework/step2-6.js +++ b/Week3/homework/step2-6.js @@ -4,13 +4,24 @@ 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); + // let arr2Flat = [].concat.apply([], arr2d); + let arr2Flat = arr.flat(); + return arr2Flat; } function flattenArray3d(arr) { - // Replace this comment and the next line with your code - console.log(arr); + const newArr3 = []; + // let arr3Flat = [].concat(...arr3d); Why is this not working? + for (let i = 0; i < arr3d.length; i++) { + for (let j = 0; j < arr3d[i].length; j++) { + for (let k = 0; k < arr3d[i][j].length; k++) { + newArr3.push(arr3d[i][j][k]); + + } + } + } + return newArr3; + } console.log(flattenArray2d(arr2d)); // -> [1, 2, 3, 4, 5, 6] @@ -18,6 +29,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, }; diff --git a/Week3/homework/step2-7.js b/Week3/homework/step2-7.js index 3e72e8551..05b641bab 100644 --- a/Week3/homework/step2-7.js +++ b/Week3/homework/step2-7.js @@ -2,8 +2,8 @@ const x = 9; function f1(val) { - val = val + 1; - return val; + val = val + 1; + return val; } f1(x); @@ -12,8 +12,8 @@ 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 +21,5 @@ f2(y); console.log(y); // Add your explanation as a comment here +// first example returns 9: x is a constant in the first example and cant change its value? +//second example is {x: 10}: Constants cant be changed, but in this case it is an object and arrays and objects can be change when assigned to a constant. \ No newline at end of file diff --git a/Week3/homework/step3-bonus.js b/Week3/homework/step3-bonus.js index 917091d61..28a06a4bd 100644 --- a/Week3/homework/step3-bonus.js +++ b/Week3/homework/step3-bonus.js @@ -3,8 +3,8 @@ 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); + const uniqueValues = values.filter((letter, i, arr) => arr.indexOf(letter) == i); + console.log(uniqueValues); } const uniqueValues = makeUnique(values); diff --git a/Week3/homework/step3.js b/Week3/homework/step3.js index 292724bf4..8f9d521b4 100644 --- a/Week3/homework/step3.js +++ b/Week3/homework/step3.js @@ -1,8 +1,10 @@ 'use strict'; function createBase(base) { - // Replace this comment and the next line with your code - console.log(base); + let sum = function (addNum) { + return base + addNum; + }; + return sum; } const addSix = createBase(6); diff --git a/package-lock.json b/package-lock.json index e89e9916d..2b047f93a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2221,12 +2221,14 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -2241,17 +2243,20 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -2368,7 +2373,8 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -2380,6 +2386,7 @@ "version": "1.0.0", "bundled": true, "dev": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -2394,6 +2401,7 @@ "version": "3.0.4", "bundled": true, "dev": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -2401,12 +2409,14 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "minipass": { "version": "2.2.4", "bundled": true, "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.1.1", "yallist": "^3.0.0" @@ -2425,6 +2435,7 @@ "version": "0.5.1", "bundled": true, "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -2505,7 +2516,8 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -2517,6 +2529,7 @@ "version": "1.4.0", "bundled": true, "dev": true, + "optional": true, "requires": { "wrappy": "1" } @@ -2638,6 +2651,7 @@ "version": "1.0.2", "bundled": true, "dev": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", diff --git a/package.json b/package.json index 1f7571946..94bd71939 100644 --- a/package.json +++ b/package.json @@ -6,9 +6,6 @@ "scripts": { "lint": "eslint \"**/homework/**/*.js\"", "test": "npm run lint", - "test-week1": "eslint Week1/homework", - "test-week2": "eslint Week2/homework && jest Week2", - "test-week3": "eslint Week3/homework && jest Week3", "test-maartjes-work": "jest maartjes-work", "test-map-filter": "jest map-filter", "test-step2-1": "jest step2-1",