diff --git a/Week2/js-exercises/.DS_Store b/Week2/js-exercises/.DS_Store
new file mode 100644
index 000000000..05c986197
Binary files /dev/null and b/Week2/js-exercises/.DS_Store differ
diff --git a/Week2/js-exercises/ex1-oddOnesOut.js b/Week2/js-exercises/ex1-oddOnesOut.js
index 4f42050ac..bc3bfecb5 100644
--- a/Week2/js-exercises/ex1-oddOnesOut.js
+++ b/Week2/js-exercises/ex1-oddOnesOut.js
@@ -8,14 +8,13 @@
*/
function doubleEvenNumbers(numbers) {
- const newNumbers = [];
- for (let i = 0; i < numbers.length; i++) {
- if (numbers[i] % 2 === 0) {
- newNumbers.push(numbers[i] * 2);
- }
- }
+ const newNumbers = numbers
+ .filter((items) => items %2 === 0)
+ .map((items) => items * 2)
+
return newNumbers;
}
+
const myNumbers = [1, 2, 3, 4];
console.log(doubleEvenNumbers(myNumbers)); // Logs "[4, 8]" to the console
\ No newline at end of file
diff --git a/Week2/js-exercises/ex2-whatsYourMondayWorth.js b/Week2/js-exercises/ex2-whatsYourMondayWorth.js
index 47cea70ba..665bd68cb 100644
--- a/Week2/js-exercises/ex2-whatsYourMondayWorth.js
+++ b/Week2/js-exercises/ex2-whatsYourMondayWorth.js
@@ -14,6 +14,13 @@
function dayWorth(tasks, hourlyRate) {
// put your code in here, the function does returns a euro formatted string
+
+ const mondaySalary = tasks
+ .map((salary) => salary.duration / 60 * hourlyRate ) //Edited as you offered :)
+ .reduce((total,item) => total + item ,0 )
+
+ let total = mondaySalary.toFixed(2);
+ return total + '€';
}
const mondayTasks = [{
@@ -35,4 +42,4 @@ const mondayTasks = [{
];
console.log(dayWorth(mondayTasks, 25))
-console.log(dayWorth(mondayTasks, 13.37))
\ No newline at end of file
+console.log(dayWorth(mondayTasks, 13.37))
diff --git a/Week2/js-exercises/ex3-lemonAllergy.js b/Week2/js-exercises/ex3-lemonAllergy.js
index 54ac8da04..5dc414df1 100644
--- a/Week2/js-exercises/ex3-lemonAllergy.js
+++ b/Week2/js-exercises/ex3-lemonAllergy.js
@@ -14,8 +14,10 @@
function takeOutLemons(basket) {
// your code goes in here. The output is a string
+ const lastFruits = basket.filter(fruit => fruit !== 'Lemon');
+ return lastFruits;
}
const fruitBasket = ['Apple', 'Lemon', 'Grapefruit', 'Lemon', 'Banana', 'Watermelon', 'Lemon'];
-console.log(takeOutLemons(fruitBasket));
\ No newline at end of file
+console.log('My mom bought me a fruit basket, containing ' + takeOutLemons(fruitBasket));
\ No newline at end of file
diff --git a/Week2/js-exercises/ex4-collectiveAge.js b/Week2/js-exercises/ex4-collectiveAge.js
index d17275cdc..4ec675099 100644
--- a/Week2/js-exercises/ex4-collectiveAge.js
+++ b/Week2/js-exercises/ex4-collectiveAge.js
@@ -10,6 +10,10 @@
function collectiveAge(people) {
// return the sum of age for all the people
+ const collectAges = people
+ .map(ages => ages.age)
+ .reduce((total,item) => total + item,0);
+ return collectAges;
}
const hackYourFutureMembers = [{
@@ -30,4 +34,4 @@ const hackYourFutureMembers = [{
},
];
-console.log("The collective age of the HYF team is: " + collectiveMembers(hackYourFutureMembers));
\ No newline at end of file
+console.log("The collective age of the HYF team is: " + collectiveAge(hackYourFutureMembers));
\ No newline at end of file
diff --git a/Week2/js-exercises/ex5-myFavoriteHobbies.html b/Week2/js-exercises/ex5-myFavoriteHobbies.html
index 06ab17d45..40b30de6b 100644
--- a/Week2/js-exercises/ex5-myFavoriteHobbies.html
+++ b/Week2/js-exercises/ex5-myFavoriteHobbies.html
@@ -1,5 +1,14 @@
+
+ My Site
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Week2/js-exercises/ex5-myFavoriteHobbies.js b/Week2/js-exercises/ex5-myFavoriteHobbies.js
index 289c68380..090bb920d 100644
--- a/Week2/js-exercises/ex5-myFavoriteHobbies.js
+++ b/Week2/js-exercises/ex5-myFavoriteHobbies.js
@@ -10,6 +10,12 @@
function createHTMLList(arr) {
// your code goes in here
+ const ul = document.getElementById('list');
+ arr.forEach(element => { //no new array needed so I changed map methot as forEach.
+ let listItem = document.createElement('li');
+ listItem.innerText = element;
+ ul.appendChild(listItem);
+ });
}
const myHobbies = [
@@ -18,4 +24,5 @@ const myHobbies = [
'Programming',
'Hanging out with friends',
'Going to the gym',
-];
\ No newline at end of file
+];
+createHTMLList(myHobbies);
diff --git a/Week2/project/.DS_Store b/Week2/project/.DS_Store
new file mode 100644
index 000000000..5ef9c0c18
Binary files /dev/null and b/Week2/project/.DS_Store differ
diff --git a/Week2/project/index.html b/Week2/project/index.html
index 664b242d3..0f92baf3d 100644
--- a/Week2/project/index.html
+++ b/Week2/project/index.html
@@ -5,10 +5,78 @@
Pomodoro Clock
+
+
+
Pomodoro Clock
+
Session Length
+
+
+
+25
+
+
+
+
+
Session
+ 25 : 00
+
+
+
+
+
diff --git a/Week2/project/index.js b/Week2/project/index.js
index 5b306f0f2..f6a2dc627 100644
--- a/Week2/project/index.js
+++ b/Week2/project/index.js
@@ -6,5 +6,80 @@
Use at least 3 functions
Display minutes and seconds
If the timer finishes the timer should be replaced by the message: Time 's up!
- *
- */
\ No newline at end of file
+ **/
+ const upButton = document.querySelector('#up-button');
+ const downButton = document.querySelector('#down-button');
+ const playButton = document.querySelector('#play-button');
+ const pauseButton = document.querySelector('#pause-button');
+ const sessionLength = document.querySelector('#session-length');
+ const timeArea = document.querySelector('#time-area');
+
+ let isClockRunning = false;
+ let workSessionDuration = parseInt(sessionLength.textContent) * 60;
+ let currentTimeLeftInSession = workSessionDuration;
+
+ playButton.addEventListener('click', () => {
+ toggleClock();
+ upButton.classList.add('disabled');
+ })
+ pauseButton.addEventListener('click', () => {
+ toggleClock();
+ isClockRunning = false;
+ clearInterval(clockTimer);
+ upButton.classList.remove('disabled');
+ })
+
+ function toggleClock(reset){
+ if (reset) {
+
+ } else {
+ if (isClockRunning === true) {
+ isClockRunning = false;
+ } else {
+ isClockRunning = true;
+ clockTimer = setInterval(() => {
+ currentTimeLeftInSession--;
+ displayCurrentTimeLeftInSession();
+ }, 1000)
+ }
+ }
+ }
+
+ function displayCurrentTimeLeftInSession(){
+ const secondsLeft = currentTimeLeftInSession;
+ let result = '';
+ const seconds = secondsLeft % 60;
+ const minutes = parseInt(secondsLeft / 60) % 60;
+ let hours = parseInt(secondsLeft / 3600);
+ function addLeadingZeroes(time) {
+ return time < 10 ? `0${time}` : time
+ }
+ if (hours > 0) result += `${hours}:`
+ result += `${addLeadingZeroes(minutes)} : ${addLeadingZeroes(seconds)}`
+ timeArea.innerText = result.toString();
+ if (minutes == 0 && seconds == 0) {
+ clearInterval(clockTimer);
+ timeArea.innerText = "Time is up!";
+ }
+ }
+
+ function upDownFunc() {
+ timeArea.innerText = `${sessionLength.textContent} : 00`;
+ console.log(typeof Number(sessionLength.textContent), Number(sessionLength.textContent));
+ currentTimeLeftInSession = parseInt(sessionLength.textContent) * 60;
+ }
+ upButton.addEventListener('click', () => {
+ if (!upButton.classList.contains('disabled')) {
+ sessionLength.textContent++;
+ upDownFunc();
+ }
+ });
+ downButton.addEventListener('click', () => {
+ if (!upButton.classList.contains('disabled')) {
+ sessionLength.textContent--;
+ upDownFunc();
+ }
+ });
+
+ timeArea.innerText = result;
+
\ No newline at end of file