diff --git a/01 - JavaScript Drum Kit/index-START.html b/01 - JavaScript Drum Kit/index-START.html index 4070d32767..569d4c0ff7 100644 --- a/01 - JavaScript Drum Kit/index-START.html +++ b/01 - JavaScript Drum Kit/index-START.html @@ -58,6 +58,26 @@ diff --git a/02 - JS and CSS Clock/index-START.html b/02 - JS and CSS Clock/index-START.html index 12f721b183..76d1e6194e 100644 --- a/02 - JS and CSS Clock/index-START.html +++ b/02 - JS and CSS Clock/index-START.html @@ -62,12 +62,38 @@ background: black; position: absolute; top: 50%; + transform-origin: 100%; + transform: rotate(90deg); + transition: all 0.05s; + transition-timing-function: cubic-bezier(0.4, 0, 1, 1); } diff --git a/03 - CSS Variables/index-START.html b/03 - CSS Variables/index-START.html index 6b9b539c09..38029ac014 100644 --- a/03 - CSS Variables/index-START.html +++ b/03 - CSS Variables/index-START.html @@ -22,6 +22,18 @@

Update CSS Variables with JS

diff --git a/04 - Array Cardio Day 1/index-START.html b/04 - Array Cardio Day 1/index-START.html index d19181b6b4..73a944f511 100644 --- a/04 - Array Cardio Day 1/index-START.html +++ b/04 - Array Cardio Day 1/index-START.html @@ -31,17 +31,45 @@ // Array.prototype.filter() // 1. Filter the list of inventors for those who were born in the 1500's + const result1 = inventors.filter(investor => investor.year >= 1500 && investor.year < 1600); + console.info('Result 1'); + console.table(result1) // Array.prototype.map() // 2. Give us an array of the inventors first and last names + const result2 = inventors.map(investor => `${investor.first} ${investor.last}`); + console.info('Result 2'); + console.table(result2) // Array.prototype.sort() // 3. Sort the inventors by birthdate, oldest to youngest + const result3 = inventors.sort((a, b) => { + const inventorABirth = a.year; + const inventorBBirth = b.year; + + return inventorBBirth > inventorABirth ? -1 : 1; + }) + console.info('Result 3'); + console.table(result3); // Array.prototype.reduce() // 4. How many years did all the inventors live all together? + const reducer = (accumulator, val) => { + return accumulator + (val.passed - val.year) + } + console.info('Result 4'); + console.log(inventors.reduce(reducer, 0)); // 5. Sort the inventors by years lived + const result5 = inventors.sort((a, b) => { + const inventorALived = a.passed - a.year; + const inventorBLived = b.passed - b.year; + + return inventorALived > inventorBLived ? 1 : -1; + }) + + console.info('Result 5'); + console.table(result5); // 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name // https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris @@ -49,10 +77,42 @@ // 7. sort Exercise // Sort the people alphabetically by last name + const result7 = people.sort((a, b) => { + let lastnameA = a.split(', ')[1]; + let lastnameB = b.split(', ')[1]; + let nameA = lastnameA.toUpperCase(); // ignore upper and lowercase + let nameB = lastnameB.toUpperCase(); + + if (nameA < nameB) { + return -1; + } + if (nameA > nameB) { + return 1; + } + + // names must be equal + return 0; + }) + + console.info('Result 7'); + console.table(result7) // 8. Reduce Exercise // Sum up the instances of each of these const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ]; + const carReducer = (accumulator, val) => { + if (!accumulator[val]) { + accumulator[val] = 0; + } + + accumulator[val] ++; + + return accumulator; + }; + + const result8 = data.reduce(carReducer, {}); + console.info('Result 8'); + console.log(result8); diff --git a/06 - Type Ahead/index-START.html b/06 - Type Ahead/index-START.html index 109c90fb36..6ff32a0055 100644 --- a/06 - Type Ahead/index-START.html +++ b/06 - Type Ahead/index-START.html @@ -17,6 +17,47 @@ diff --git a/10 - Hold Shift and Check Checkboxes/index-START.html b/10 - Hold Shift and Check Checkboxes/index-START.html index 4fd2936ddc..22b53cf1ce 100644 --- a/10 - Hold Shift and Check Checkboxes/index-START.html +++ b/10 - Hold Shift and Check Checkboxes/index-START.html @@ -96,6 +96,38 @@ diff --git a/11 - Custom Video Player/index.html b/11 - Custom Video Player/index.html index 57b3260bc2..6f4a90599c 100644 --- a/11 - Custom Video Player/index.html +++ b/11 - Custom Video Player/index.html @@ -19,6 +19,7 @@ + diff --git a/11 - Custom Video Player/scripts.js b/11 - Custom Video Player/scripts.js index e69de29bb2..a2c3f950a4 100644 --- a/11 - Custom Video Player/scripts.js +++ b/11 - Custom Video Player/scripts.js @@ -0,0 +1,69 @@ +// get elements +const video = document.querySelector('.viewer'); +const progress = document.querySelector('.progress'); +const progressFilled = document.querySelector('.progress__filled'); +const skipButtons = document.querySelectorAll('[data-skip]'); +const rangeButtons = document.querySelectorAll('.player__slider'); +const toggleButton = document.querySelector('.toggle'); +const fullscreen = document.querySelector('.fullscreen'); + +console.log('skip b', skipButtons); + +// handle events +function handlePause() { + const method = video.paused ? 'play' : 'pause'; + video[method](); +} + +function handlePauseEvent() { + const icon = this.paused ? '►' : '❚ ❚'; + console.log('icon', icon); + toggleButton.textContent = icon; +} + +function handleSkip() { + console.log(this.dataset); + video.currentTime += parseFloat(this.dataset.skip); +} + +function handleRange() { + video[this.name] = this.value; +} + +function handleTimeUpdate() { + const percent = (this.currentTime / this.duration) * 100; + progressFilled.style.flexBasis = `${percent}%`; +} + +function toggleFullScreen() { + if (!document.fullscreenElement) { + video.requestFullscreen(); + } else { + if (document.exitFullscreen) { + video.exitFullscreen(); + } + } +} + +function updateProgressBar(e) { + const scrubTime = (e.offsetX / progress.offsetWidth) * video.duration; + video.currentTime = scrubTime; +} + +// hook events +toggleButton.addEventListener('click', handlePause) +fullscreen.addEventListener('click', toggleFullScreen); +video.addEventListener('click', handlePause) +video.addEventListener('pause', handlePauseEvent) +video.addEventListener('play', handlePauseEvent) +video.addEventListener('timeupdate', handleTimeUpdate); + +skipButtons.forEach(button => button.addEventListener('click', handleSkip)) + +rangeButtons.forEach(button => button.addEventListener('click', handleRange)) + +let mousedown = false; +progress.addEventListener('click', updateProgressBar); +progress.addEventListener('mousemove', (e) => mousedown && updateProgressBar(e)); +progress.addEventListener('mousedown', () => mousedown = true); +progress.addEventListener('mouseup', () => mousedown = false);