diff --git a/01 - JavaScript Drum Kit/index-START.html b/01 - JavaScript Drum Kit/index-START.html index 4070d32767..724bc6dc12 100644 --- a/01 - JavaScript Drum Kit/index-START.html +++ b/01 - JavaScript Drum Kit/index-START.html @@ -58,7 +58,28 @@ diff --git a/02 - JS and CSS Clock/index-START.html b/02 - JS and CSS Clock/index-START.html index 12f721b183..3f07399214 100644 --- a/02 - JS and CSS Clock/index-START.html +++ b/02 - JS and CSS Clock/index-START.html @@ -62,13 +62,52 @@ background: black; position: absolute; top: 50%; + /* Move rotate axis to the right-most edge */ + transform-origin: 100%; + /* Align hands at 12 o clock to start */ + transform: rotate(90deg); + /* Smooth out the movement when hand rotates */ + transition: all 0.05s; + transition-timing-function: cubic-bezier(0.1, 2.7, 0.58, 1); + } + + .hour-hand { + background-color: green; + } + + .second-hand { + background-color: red; } diff --git a/03 - CSS Variables/index-START.html b/03 - CSS Variables/index-START.html index 6b9b539c09..4bd35e4dc9 100644 --- a/03 - CSS Variables/index-START.html +++ b/03 - CSS Variables/index-START.html @@ -21,6 +21,21 @@

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..de9d1168cd 100644 --- a/04 - Array Cardio Day 1/index-START.html +++ b/04 - Array Cardio Day 1/index-START.html @@ -31,29 +31,86 @@ // Array.prototype.filter() // 1. Filter the list of inventors for those who were born in the 1500's + const fifteen = inventors.filter(inventor => { + return inventor.year >= 1500 && inventor.year < 1600; + }); + console.table(fifteen); // Array.prototype.map() // 2. Give us an array of the inventors first and last names + const names = inventors.map(inventor => `${inventor.first} ${inventor.last}`); + console.table(names); // Array.prototype.sort() // 3. Sort the inventors by birthdate, oldest to youngest + const ordered = inventors.sort((firstPerson, secondPerson) => { + if (firstPerson.year < secondPerson.year) { + return -1; + } + + if (firstPerson.year > secondPerson.year) { + return 1; + } + }); + console.table(ordered); // Array.prototype.reduce() // 4. How many years did all the inventors live all together? + const totalYears = inventors.reduce((total, inventor) => { + let yearsLived = inventor.passed - inventor.year; + return total += yearsLived; + }, 0); + console.log(totalYears); // 5. Sort the inventors by years lived + const sortedByYearsLived = inventors.sort((firstPerson, secondPerson) => { + firstPersonAge = firstPerson.passed - firstPerson.year; + secondPersonAge = secondPerson.passed - secondPerson.year; + + return firstPersonAge - secondPersonAge; + }); + console.table(sortedByYearsLived); // 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name // https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris - + const boulevards = Array.from(document.querySelectorAll('.mw-category-group ul li a')); + const de = boulevards + .map(boulevard => boulevard.textContent) + .filter(boulevard => boulevard.includes('de')); // 7. sort Exercise // Sort the people alphabetically by last name + const sortedByLastName = people.sort((firstPerson, secondPerson) => { + const [aLast, aFirst] = firstPerson.split(', '); + const [bLast, bFirst] = secondPerson.split(', '); + + if (aLast < bLast) { + return -1; + } + + if (aLast > bLast) { + return 1; + } + + return 0; + }); + console.log(sortedByLastName); // 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 data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck', 'pogo stick' ]; + + const transportation = data.reduce((obj, item) => { + let entry = obj[item]; + + if (!entry) { + obj[item] = 0; + } + obj[item]++; + return obj; + }, {}); + console.log(transportation); diff --git a/05 - Flex Panel Gallery/index-START.html b/05 - Flex Panel Gallery/index-START.html index 71d1c26f00..87e827aa64 100644 --- a/05 - Flex Panel Gallery/index-START.html +++ b/05 - Flex Panel Gallery/index-START.html @@ -26,6 +26,7 @@ .panels { min-height: 100vh; overflow: hidden; + display: flex; } .panel { @@ -43,6 +44,11 @@ font-size: 20px; background-size: cover; background-position: center; + flex: 1; + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; } .panel1 { background-image:url(https://source.unsplash.com/gYl-UtwNg_I/1500x1500); } @@ -56,6 +62,26 @@ margin: 0; width: 100%; transition: transform 0.5s; + flex: 1 0 auto; + display: flex; + justify-content: center; + align-items: center; + } + + .panel > *:first-child { + transform: translateY(-100%); + } + + .panel.open-active > *:first-child { + transform: translateY(0); + } + + .panel > *:last-child { + transform: translateY(100%); + } + + .panel.open-active > *:last-child { + transform: translateY(0); } .panel p { @@ -70,6 +96,7 @@ } .panel.open { + flex: 5; font-size: 40px; } @@ -105,7 +132,20 @@ diff --git a/06 - Type Ahead/index-START.html b/06 - Type Ahead/index-START.html index 109c90fb36..acf807765a 100644 --- a/06 - Type Ahead/index-START.html +++ b/06 - Type Ahead/index-START.html @@ -17,6 +17,43 @@ diff --git a/07 - Array Cardio Day 2/index-START.html b/07 - Array Cardio Day 2/index-START.html index 969566ff78..b1989cd98b 100644 --- a/07 - Array Cardio Day 2/index-START.html +++ b/07 - Array Cardio Day 2/index-START.html @@ -26,15 +26,40 @@ // Some and Every Checks // Array.prototype.some() // is at least one person 19 or older? + const isAdult = people.some(person => { + const thisYear = new Date().getFullYear(); + return (thisYear - person.year) >= 19; + }); + console.log(isAdult); + // Array.prototype.every() // is everyone 19 or older? + const areAdults = people.every(person => { + const thisYear = new Date().getFullYear(); + return (thisYear - person.year) >= 19; + }); + console.log(areAdults); // Array.prototype.find() // Find is like filter, but instead returns just the one you are looking for // find the comment with the ID of 823423 + const comment = comments.find(comment => comment.id == 823423); + console.log(comment); // Array.prototype.findIndex() // Find the comment with this ID // delete the comment with the ID of 823423 + const index = comments.findIndex(comment => comment.id == 823423); + + // Delete in-place with splice + // comments.splice(index, 1); + + const newComments = [ + ...comments.slice(0, index), + ...comments.slice(index +1) + ]; + + console.log(newComments); + diff --git a/08 - Fun with HTML5 Canvas/index-START.html b/08 - Fun with HTML5 Canvas/index-START.html index 9da9b5b3c5..9d08ed14ad 100644 --- a/08 - Fun with HTML5 Canvas/index-START.html +++ b/08 - Fun with HTML5 Canvas/index-START.html @@ -7,6 +7,64 @@ diff --git a/17 - Sort Without Articles/index-START.html b/17 - Sort Without Articles/index-START.html index 2b6c9546e9..df4db7511c 100644 --- a/17 - Sort Without Articles/index-START.html +++ b/17 - Sort Without Articles/index-START.html @@ -48,7 +48,15 @@ diff --git a/18 - Adding Up Times with Reduce/index-START.html b/18 - Adding Up Times with Reduce/index-START.html index abdf4c91af..eab68fe96b 100644 --- a/18 - Adding Up Times with Reduce/index-START.html +++ b/18 - Adding Up Times with Reduce/index-START.html @@ -182,6 +182,23 @@ diff --git a/19 - Webcam Fun/index.html b/19 - Webcam Fun/index.html index 682192dbb5..89f5a5221e 100755 --- a/19 - Webcam Fun/index.html +++ b/19 - Webcam Fun/index.html @@ -9,8 +9,8 @@
- - +
diff --git a/19 - Webcam Fun/scripts.js b/19 - Webcam Fun/scripts.js index 00355f5a9c..c6ad42946e 100644 --- a/19 - Webcam Fun/scripts.js +++ b/19 - Webcam Fun/scripts.js @@ -3,3 +3,100 @@ const canvas = document.querySelector('.photo'); const ctx = canvas.getContext('2d'); const strip = document.querySelector('.strip'); const snap = document.querySelector('.snap'); + +function getVideo() { + navigator.mediaDevices.getUserMedia({ video: true, audio: false }) + .then(localMediaStream => { + video.srcObject = localMediaStream; + video.play(); + }) + .catch(err => { + console.log(err); + }); +} + +function paintToCanvas() { + const width = video.videoWidth; + const height = video.videoHeight; + canvas.width = width; + canvas.height = height; + + return setInterval(() => { + ctx.drawImage(video, 0 , 0, width, height); + // Take pixels out + let pixels = ctx.getImageData(0, 0, width, height); + // mess with them + //pixels = redEffect(pixels); + + pixels = rgbSplit(pixels); + ctx.globalAlpha = 0.1; + + //pixels = greenScreen(pixels); + // Put them back + ctx.putImageData(pixels, 0, 0); + }, 16); +} + +function snapPhoto() { + // Play sound + snap.currentTime = 0; + snap.play(); + + // Take data out of canvas + const data = canvas.toDataURL('image/jpeg'); + const link = document.createElement('a'); + link.href = data; + link.setAttribute('download', 'cool'); + link.innerHTML = `Coolest girl` + strip.insertBefore(link, strip.firstChild); +} + +function redEffect(pixels) { + for(let i = 0; i < pixels.data.length; i += 4) { + pixels.data[i + 0] = pixels.data[i + 0] + 200; // RED + pixels.data[i + 1] = pixels.data[i + 1] - 50; // GREEN + pixels.data[i + 2] = pixels.data[i + 2] * 0.5; // Blue + } + return pixels; +} + +function rgbSplit(pixels) { + for(let i = 0; i < pixels.data.length; i += 4) { + pixels.data[i - 150] = pixels.data[i + 0]; // RED + pixels.data[i + 500] = pixels.data[i + 1]; // GREEN + pixels.data[i - 550] = pixels.data[i + 2]; // Blue + } + return pixels; +} + +function greenScreen(pixels) { + const levels = {}; + + document.querySelectorAll('.rgb input').forEach((input) => { + levels[input.name] = input.value; + }); + + for (i = 0; i < pixels.data.length; i = i + 4) { + red = pixels.data[i + 0]; + green = pixels.data[i + 1]; + blue = pixels.data[i + 2]; + alpha = pixels.data[i + 3]; + + if (red >= levels.rmin + && green >= levels.gmin + && blue >= levels.bmin + && red <= levels.rmax + && green <= levels.gmax + && blue <= levels.bmax) { + // take it out! + pixels.data[i + 3] = 0; + } + } + + return pixels; +} + +getVideo(); + +// Once the video is playing, it emits the 'canplay' event +video.addEventListener('canplay', paintToCanvas); \ No newline at end of file diff --git a/20 - Speech Detection/index-START.html b/20 - Speech Detection/index-START.html index 31b4042563..a1c7763f13 100644 --- a/20 - Speech Detection/index-START.html +++ b/20 - Speech Detection/index-START.html @@ -12,7 +12,28 @@ diff --git a/22 - Follow Along Link Highlighter/index-START.html b/22 - Follow Along Link Highlighter/index-START.html index 8476112b5e..b0d270252d 100644 --- a/22 - Follow Along Link Highlighter/index-START.html +++ b/22 - Follow Along Link Highlighter/index-START.html @@ -27,6 +27,27 @@ diff --git a/23 - Speech Synthesis/index-START.html b/23 - Speech Synthesis/index-START.html index e890008d36..8b8880b59c 100644 --- a/23 - Speech Synthesis/index-START.html +++ b/23 - Speech Synthesis/index-START.html @@ -35,6 +35,39 @@

The Voiceinator 5000

const options = document.querySelectorAll('[type="range"], [name="text"]'); const speakButton = document.querySelector('#speak'); const stopButton = document.querySelector('#stop'); + msg.text = document.querySelector('[name="text"').value; + + function populateVoices() { + voices = this.getVoices(); + const voiceOptions = voices + .map(voice => ``) + .join(''); + voicesDropdown.innerHTML = voiceOptions; + } + + function setVoice() { + msg.voice = voices.find(voice => voice.name == this.value); + toggle(); + } + + function toggle(startOver = true) { + speechSynthesis.cancel(); + if (startOver) { + speechSynthesis.speak(msg); + } + } + + function setOption() { + msg[this.name] = this.value; + toggle(); + } + + speechSynthesis.addEventListener('voiceschanged', populateVoices); + voicesDropdown.addEventListener('change', setVoice); + options.forEach(option => option.addEventListener('change', setOption)); + speakButton.addEventListener('click', toggle); + // stopButton.addEventListener('click', toggle.bind(null, false)); + stopButton.addEventListener('click', () => toggle(false)); diff --git a/24 - Sticky Nav/index-START.html b/24 - Sticky Nav/index-START.html index e7bc67e9a5..e9a2111c7c 100644 --- a/24 - Sticky Nav/index-START.html +++ b/24 - Sticky Nav/index-START.html @@ -54,7 +54,20 @@

A story about getting lost.

diff --git a/24 - Sticky Nav/style-START.css b/24 - Sticky Nav/style-START.css index b83b9c01ae..1e5ba260d1 100644 --- a/24 - Sticky Nav/style-START.css +++ b/24 - Sticky Nav/style-START.css @@ -25,6 +25,10 @@ body { transition: transform 0.5s; } +.fixed-nav .site-wrap { + transform: scale(1); +} + header { text-align: center; height: 50vh; @@ -50,6 +54,11 @@ nav { z-index: 1; } +.fixed-nav nav { + position: fixed; + box-shadow: 0 5px rgba(0,0,0,0.1); +} + nav ul { margin: 0; padding:0; @@ -69,11 +78,15 @@ li.logo { max-width: 0; overflow: hidden; background: white; - transition: all .5s; + transition: all 1s; font-weight: 600; font-size: 30px; } +.fixed-nav li.logo { + max-width: 500px; +} + li.logo a { color: black; } diff --git a/25 - Event Capture, Propagation, Bubbling and Once/index-START.html b/25 - Event Capture, Propagation, Bubbling and Once/index-START.html index 7bd5931e01..a346e1ec16 100644 --- a/25 - Event Capture, Propagation, Bubbling and Once/index-START.html +++ b/25 - Event Capture, Propagation, Bubbling and Once/index-START.html @@ -42,7 +42,17 @@ diff --git a/26 - Stripe Follow Along Nav/index-START.html b/26 - Stripe Follow Along Nav/index-START.html index 608d0a6716..e736077fb1 100644 --- a/26 - Stripe Follow Along Nav/index-START.html +++ b/26 - Stripe Follow Along Nav/index-START.html @@ -220,6 +220,44 @@

Cool

diff --git a/27 - Click and Drag/index-START.html b/27 - Click and Drag/index-START.html index b8609315f7..2268ff4be1 100644 --- a/27 - Click and Drag/index-START.html +++ b/27 - Click and Drag/index-START.html @@ -35,6 +35,36 @@ diff --git a/28 - Video Speed Controller/index-START.html b/28 - Video Speed Controller/index-START.html index 8bd536b18b..eb0bc3b135 100644 --- a/28 - Video Speed Controller/index-START.html +++ b/28 - Video Speed Controller/index-START.html @@ -15,6 +15,23 @@ diff --git a/29 - Countdown Timer/scripts-START.js b/29 - Countdown Timer/scripts-START.js index e69de29bb2..00a473aea7 100644 --- a/29 - Countdown Timer/scripts-START.js +++ b/29 - Countdown Timer/scripts-START.js @@ -0,0 +1,64 @@ +let countdown; +const timerDisplay = document.querySelector('.display__time-left'); +const endTime = document.querySelector('.display__end-time'); +const buttons = document.querySelectorAll('[data-time]'); + +function timer(seconds) { + // clear existing timers + clearInterval(countdown); + + const now = Date.now(); + const then = now + seconds * 1000; + displayTimeLeft(seconds); // Make sure first second is displayed + dispayEndTime(then); + + countdown = setInterval(() => { + const secondsLeft = Math.round((then - Date.now()) / 1000); + // Check if we should stop + if (secondsLeft < 0) { + clearInterval(countdown); + return; + } + + displayTimeLeft(secondsLeft); + }, 1000) +} + +function displayTimeLeft(seconds) { + const minutes = Math.floor(seconds / 60); + const remainderSeconds = seconds % 60; + const display = `${minutes}:${zeroPadSeconds(remainderSeconds)}`; + + timerDisplay.textContent = display; + document.title = display; +} + +function dispayEndTime(timestamp) { + const end = new Date(timestamp); + const hour = end.getHours(); + const minutes = end.getMinutes(); + endTime.textContent = `Be back at ${hour}:${zeroPadMinutes(minutes)}`; +} + +function zeroPadSeconds(seconds) { + const padding = seconds < 10 ? '0' : ''; + return `${padding}${seconds}`; +} + +function zeroPadMinutes(minutes) { + const padding = minutes < 10 ? '0' : ''; + return `${padding}${minutes}`; +} + +function startTimer() { + const seconds = parseInt(this.dataset.time); + timer(seconds); +} + +buttons.forEach(button => button.addEventListener('click', startTimer)); +document.customForm.addEventListener('submit', function(e) { + e.preventDefault(); + const minutes = this.minutes.value; + timer(minutes * 60); + this.reset(); +}) \ No newline at end of file diff --git a/30 - Whack A Mole/index-START.html b/30 - Whack A Mole/index-START.html index 2014ff458c..40b65e0c99 100644 --- a/30 - Whack A Mole/index-START.html +++ b/30 - Whack A Mole/index-START.html @@ -36,7 +36,54 @@

Whack-a-mole! 0

const holes = document.querySelectorAll('.hole'); const scoreBoard = document.querySelector('.score'); const moles = document.querySelectorAll('.mole'); + let lastHole; + let timeUp = false; + let score = 0; + function randomTime(min, max) { + return Math.round(Math.random() * (max - min) + min); + } + + function randomHole(holes) { + const index = Math.floor(Math.random() * holes.length); + const hole = holes[index]; + + if (hole === lastHole) { + return randomHole(holes); + } + + lastHole = hole; + return hole; + } + + function peep() { + const time = randomTime(200, 1000); + const hole = randomHole(holes); + + hole.classList.add('up'); + setTimeout(() => { + hole.classList.remove('up'); + if(!timeUp) peep(); + }, time); + } + + function startGame() { + scoreBoard.textContent = 0; + timeUp = false; + score = 0; + peep(); + + setTimeout(() => timeUp = true, 10000); + } + + function bonk(e) { + if(!e.isTrusted) return; // cheater! + score ++; + this.classList.remove('up'); + scoreBoard.textContent = score; + } + + moles.forEach(mole => mole.addEventListener('click', bonk));