diff --git a/Week1/homework/index.html b/Week1/homework/index.html index b22147cd1..3d00f5bc7 100644 --- a/Week1/homework/index.html +++ b/Week1/homework/index.html @@ -1 +1 @@ - \ No newline at end of file + diff --git a/Week1/homework/style.css b/Week1/homework/style.css index bab13ec23..44cb05eeb 100644 --- a/Week1/homework/style.css +++ b/Week1/homework/style.css @@ -1 +1 @@ -/* add your styling here */ \ No newline at end of file +/* add your styling here */ diff --git a/Week2/exercises/arrayExercise.js b/Week2/exercises/arrayExercise.js new file mode 100644 index 000000000..6c9c96f4c --- /dev/null +++ b/Week2/exercises/arrayExercise.js @@ -0,0 +1,91 @@ +'use strict'; + +/*Write a Javascript function to get first element of an array. +Passing a parameter 'n' will return the fist 'n' elements of the array.*/ + +const numbers = [' one ', ' two ', ' three ', ' four ', ' five ']; +document.getElementById('array').innerHTML = 'Array :' + numbers; + +function getFirstElement(array, index) { + const newArray = array.slice(0, index); + return newArray; +} + +function callFistElement() { + document.getElementById('exe-1').innerHTML = getFirstElement(numbers, 3); +} + +// ************************************** // + +/* Write a Javascript program which accept a number as input an insert dashes (-) between +each two even numbers.For example if you accept 025468 the output should be 0-254-6-8. */ + +function dashInsert(str) { + var arrayNumbers = str.split(''); + var newString = ''; + for (var i = 0; i < arrayNumbers.length; i++) { + if (arrayNumbers[i] % 2 === 0 && arrayNumbers[i + 1] % 2 === 0) { + newString = newString + arrayNumbers[i] + '-'; + } else { + newString = newString + arrayNumbers[i]; + } + } + return newString; +} +function callDashInsert() { + const inputValue = document.querySelector('input').value; + document.getElementById('exe-2').innerHTML = dashInsert(inputValue); +} + +// ************************************** // + +/* write a Javascript program to find the most frequent item of an array.*/ + +const animals = [' cat ', ' dog ', ' bird ', ' lion ', ' cat ', ' dog ', ' cat ']; +document.getElementById('animals').innerHTML = 'Array :' + animals; + +function mostFrequentItem(array) { + var result = array[0]; + var compare = 0; + for (var i = 0; i < array.length; i++) { + var count = 0; + for (var j = 0; j < array.length; j++) { + if (array[i] === array[j]) { + count++; + } + } + if (count > compare) { + compare = count; + result = array[i]; + } + } + return result; +} + +function callFrequentItem() { + document.getElementById('exe-3').innerHTML = mostFrequentItem(animals); +} + +// ************************************** // + +/* write a Javascript program which accept a string as input and swap the case of each +character.For example if you input 'The Quick Brown Fox' the output should be +'tHE qUICK bROWN fOX' .*/ + +function caseAlter(txt) { + var output = ''; + + for (var i = 0; i < txt.length; i++) { + if (txt[i] == txt[i].toUpperCase()) { + output += txt[i].toLowerCase(); + } else { + output += txt[i].toUpperCase(); + } + } + + return output; +} +function callCaseAlter() { + const input = document.getElementById('case-alter').value; + document.getElementById('exe-4').innerHTML = caseAlter(input); +} diff --git a/Week2/exercises/index.html b/Week2/exercises/index.html new file mode 100644 index 000000000..5a2dcb769 --- /dev/null +++ b/Week2/exercises/index.html @@ -0,0 +1,29 @@ + + + + + + + week2 exercise1 + + +

Exercise-1

+

+ +

+

Exercise-2

+ +

+ +

Exercise-3

+

+ +

+

Exercise-4

+

+ +

+ + + + diff --git a/Week2/exercises/jsonExercise.js b/Week2/exercises/jsonExercise.js new file mode 100644 index 000000000..7e3eee4ca --- /dev/null +++ b/Week2/exercises/jsonExercise.js @@ -0,0 +1,40 @@ +//Write a JavaScript program to get the length of an JavaScript object. + +var object; +object = { + "Country": "Belgium", + "Capital": "Brussels", + "Language": "French-Dutch", +}; + +var getTheObjLength = key => { + return Object.keys(key).length; +}; + +console.log(getTheObjLength(object)); + + +//Write a JavaScript function to check if an object contains given property. + +var checkHaskey = (obj, key) => { + if (obj.hasOwnProperty(key)) { + console.log("Yes, I have " + key); + } else { + console.log("I have not " + key + " property"); + } + +}; +console.log(checkHaskey(object, "Capital")); + + +//Write a JavaScript program to create a Clock. Console, every second :”14:37:42”,”14:37:43", “14:37:44”, "14:37:45" + + +function myClock() { + var today = new Date(); + var hours = today.getHours(); + var minutes = today.getMinutes(); + var seconds = today.getSeconds(); + console.log(hours + ":" + minutes + ":" + seconds); +}; +setInterval(myClock, 1000); diff --git a/Week2/homework/maartjes-work.js b/Week2/homework/maartjes-work.js index 49772eb44..2574e0229 100644 --- a/Week2/homework/maartjes-work.js +++ b/Week2/homework/maartjes-work.js @@ -46,16 +46,20 @@ 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 taskDurations = tasks + .map(task => task.duration / 60) + .filter(taskDuration => taskDuration >= 2) + .map(duration => duration * hourlyRate) + .reduce((acc, salary) => acc + salary) + .toFixed(2); + 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 €${'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 = { diff --git a/Week2/homework/map-filter.js b/Week2/homework/map-filter.js index c8e8a88c1..c549047a7 100644 --- a/Week2/homework/map-filter.js +++ b/Week2/homework/map-filter.js @@ -1,8 +1,9 @@ 'use strict'; function doubleOddNumbers(numbers) { - // Replace this comment and the next line with your code - console.log(numbers); + const doubleOddArr = numbers.filter(num => num % 2) + .map(num => num * 2) + return doubleOddArr; } const myNumbers = [1, 2, 3, 4];