From 2239a68ecf11bfa9bed0714136ea1ae9f5d66474 Mon Sep 17 00:00:00 2001 From: dhemir17 Date: Sun, 26 Apr 2020 01:10:28 +0200 Subject: [PATCH 1/3] js2 week2 homework done --- Week2/js-exercises/.DS_Store | Bin 0 -> 6148 bytes Week2/js-exercises/ex1-oddOnesOut.js | 11 ++- .../js-exercises/ex2-whatsYourMondayWorth.js | 7 ++ Week2/js-exercises/ex3-lemonAllergy.js | 4 +- Week2/js-exercises/ex4-collectiveAge.js | 6 +- Week2/js-exercises/ex5-myFavoriteHobbies.html | 9 ++ Week2/js-exercises/ex5-myFavoriteHobbies.js | 12 ++- Week2/project/.DS_Store | Bin 0 -> 6148 bytes Week2/project/index.html | 68 +++++++++++++++ Week2/project/index.js | 79 +++++++++++++++++- 10 files changed, 185 insertions(+), 11 deletions(-) create mode 100644 Week2/js-exercises/.DS_Store create mode 100644 Week2/project/.DS_Store diff --git a/Week2/js-exercises/.DS_Store b/Week2/js-exercises/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..05c9861973d6c3283caa4e72d4f8d3500bb649b4 GIT binary patch literal 6148 zcmeHK%Sr=55UhzoB3>eT2zuG07lrt^Z$b=u5J3;(P4mD+@_@udz3pfCQGS4bqt!h_ zNU|&FMMS!nnd<48uHC6wc6I=`>ZDZ$iU0~Mg1I$T87BQwQkDymRiaalAzHjHFhDys z+5&%30a?2ZuGTZk*u(t#jk%5!JYpXY7@zfq%|>t7;AnYO>MXk-YV?2|WjG+i6FRtK z))+Trn_z@<;(%|(9bRxvf5hHSChOZ0>!z|ElC?*#uRIm{(i-8Od>PN?E|*xgl;wyl zO)~iGCZC~;DSIm9X=n1hFY#2(mr=K0t(GX+cmQ{Wp4aL*Pitb4TD6fgx$ftdpGeTY~DBLFea zuo`{&L6n>*U>q><$R3*WsYIXZ!V$yybjG7FE)JM@^yzTn@ZrLpT{xjQy*v3M9S#?J zwAvIf1r`-p@y(*_|0iFc{}+?2WeS)A|4IRuuU*xuoKo0ZQL literal 0 HcmV?d00001 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..6dcbe8e71 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 * hourlyRate / 60 ) + .reduce((total,item) => total + item ,0 ) + + let total = mondaySalary.toFixed(2); + return total + '€'; } const mondayTasks = [{ 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..71db7e59d 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'); + const newArr = arr.map(hobby => { + let listItem = document.createElement('li'); + listItem.innerText = hobby; + ul.appendChild(listItem); + }) } const myHobbies = [ @@ -18,4 +24,8 @@ 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 0000000000000000000000000000000000000000..5ef9c0c185f6f0413f418f91ad74aa3c47b924ce GIT binary patch literal 6148 zcmeHKF-`)S-xyefdzm$U5Gb@scBt4vAxI$i#_8NC%DBk9?(sye@=*dfIB>5gBuL^ z7v1)H-EG%g*UO#Lk3Y;f(hCha_juZ=f8VJ$QifC@6-WhAfm9$BP|udl4;?e60;xbM z@U4LU50x%#fxV;sIv8|(*ZNE-RMp$=yVj@ zna_!xOWaV3?aq9)a+KznF%?J!#tQ8FbfNx#M*rphKPKfY6-WjCl>%k9x?C;!Nzq#; vAE#bh=~whGW381lj1B>us1+X#>Z-=9Yk|F^(U~_oF%JULB`p>B3k5y_taB(H literal 0 HcmV?d00001 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 From 092af1ccbb8df053aa7c84481b6bde847c6d234c Mon Sep 17 00:00:00 2001 From: Burak Sabah <30929892+dhemir17@users.noreply.github.com> Date: Fri, 29 May 2020 16:11:37 +0200 Subject: [PATCH 2/3] Edited :) --- Week2/js-exercises/ex2-whatsYourMondayWorth.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Week2/js-exercises/ex2-whatsYourMondayWorth.js b/Week2/js-exercises/ex2-whatsYourMondayWorth.js index 6dcbe8e71..665bd68cb 100644 --- a/Week2/js-exercises/ex2-whatsYourMondayWorth.js +++ b/Week2/js-exercises/ex2-whatsYourMondayWorth.js @@ -16,7 +16,7 @@ function dayWorth(tasks, hourlyRate) { // put your code in here, the function does returns a euro formatted string const mondaySalary = tasks - .map((salary) => salary.duration * hourlyRate / 60 ) + .map((salary) => salary.duration / 60 * hourlyRate ) //Edited as you offered :) .reduce((total,item) => total + item ,0 ) let total = mondaySalary.toFixed(2); @@ -42,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)) From a8db682196df498ffbe577be901c7bd8df8d8f56 Mon Sep 17 00:00:00 2001 From: Burak Sabah <30929892+dhemir17@users.noreply.github.com> Date: Fri, 29 May 2020 16:20:36 +0200 Subject: [PATCH 3/3] Map method is changed by forEach, new arrayRemoved --- Week2/js-exercises/ex5-myFavoriteHobbies.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Week2/js-exercises/ex5-myFavoriteHobbies.js b/Week2/js-exercises/ex5-myFavoriteHobbies.js index 71db7e59d..090bb920d 100644 --- a/Week2/js-exercises/ex5-myFavoriteHobbies.js +++ b/Week2/js-exercises/ex5-myFavoriteHobbies.js @@ -11,11 +11,11 @@ function createHTMLList(arr) { // your code goes in here const ul = document.getElementById('list'); - const newArr = arr.map(hobby => { + arr.forEach(element => { //no new array needed so I changed map methot as forEach. let listItem = document.createElement('li'); - listItem.innerText = hobby; + listItem.innerText = element; ul.appendChild(listItem); - }) + }); } const myHobbies = [ @@ -25,7 +25,4 @@ const myHobbies = [ 'Hanging out with friends', 'Going to the gym', ]; - createHTMLList(myHobbies); - -