diff --git a/01 - JavaScript Drum Kit/index-START.html b/01 - JavaScript Drum Kit/index-START.html index 4070d32767..c2de015606 100644 --- a/01 - JavaScript Drum Kit/index-START.html +++ b/01 - JavaScript Drum Kit/index-START.html @@ -58,7 +58,24 @@ diff --git a/02 - JS + CSS Clock/index-START.html b/02 - JS + CSS Clock/index-START.html index 2712384201..94c1eee67b 100644 --- a/02 - JS + CSS Clock/index-START.html +++ b/02 - JS + CSS Clock/index-START.html @@ -53,6 +53,7 @@ width: 100%; height: 100%; transform: translateY(-3px); /* account for the height of the clock hands */ + } .hand { @@ -61,13 +62,36 @@ background:black; position: absolute; top:50%; + transform-origin: 100%; + transition: all 0.05s; + transition-timing-function: cubic-bezier(0.56, 2.74, 0.58, 1); } diff --git a/03 - CSS Variables/index-START.html b/03 - CSS Variables/index-START.html index 7171607a8b..6e6fa931f0 100644 --- a/03 - CSS Variables/index-START.html +++ b/03 - CSS Variables/index-START.html @@ -21,10 +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 4162bce339..db44d8459a 100644 --- a/04 - Array Cardio Day 1/index-START.html +++ b/04 - Array Cardio Day 1/index-START.html @@ -33,29 +33,50 @@ // Array.prototype.filter() // 1. Filter the list of inventors for those who were born in the 1500's + const fifteens = inventors.filter(inventor => inventor.year >= 1500 && inventor.year < 1600); + console.log(fifteens); // 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.log(names); // Array.prototype.sort() // 3. Sort the inventors by birthdate, oldest to youngest + const sorted = inventors.sort((a, b) => a.year - b.year); + console.table(sorted); // Array.prototype.reduce() // 4. How many years did all the inventors live? + const total = inventors.reduce((acc, current) => acc + (current.passed - current.year), 0); + console.log(total); // 5. Sort the inventors by years lived + const sortedTotal = inventors.sort((a, b) => (a.passed - a.year) - (b.passed - b.year)); + console.table(sortedTotal); // 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 paris = ["Boulevards of Paris", "City walls of Paris", "Thiers wall", "Wall of Charles V", "Wall of Philip II Augustus", "City gates of Paris", "Haussmann's renovation of Paris", "Boulevards of the Marshals", "Boulevard Auguste-Blanqui", "Boulevard Barbès", "Boulevard Beaumarchais", "Boulevard de l'Amiral-Bruix", "Boulevard de Strasbourg", "Boulevard des Capucines", "Boulevard de la Chapelle", "Boulevard de Clichy", "Boulevard du Crime", "Boulevard Haussmann", "Boulevard de l'Hopital", "Boulevard des Italiens", "Boulevard de la Madeleine", "Boulevard de Magenta", "Boulevard Montmartre", "Boulevard du Montparnasse", "Boulevard Raspail", "Boulevard Richard-Lenoir", "Boulevard de Rochechouart", "Boulevard Saint-Germain", "Boulevard Saint-Michel", "Boulevard de Sébastopol", "Boulevard du Temple", "Boulevard Voltaire", "Boulevard de la Zone"]; + // console.log(paris.filter(q => q.includes("de"))); // 7. sort Exercise // Sort the people alphabetically by last name + const pplSorted = people + .map(person => person.split(', ')) + .sort(([aLast, _a], [bLast, _b]) => aLast > bLast ? 1 : -1) + .map(([last, first]) => `${first} ${last}`); + + console.log(pplSorted); // 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 counts = data.reduce((output, current) => { + output[current] = (output[current] || 0) + 1; + return output; + }, {}); + console.log(counts); diff --git a/05 - Flex Panel Gallery/index-START.html b/05 - Flex Panel Gallery/index-START.html index e1d643ad5c..6122c806a9 100644 --- a/05 - Flex Panel Gallery/index-START.html +++ b/05 - Flex Panel Gallery/index-START.html @@ -24,9 +24,11 @@ .panels { min-height:100vh; overflow: hidden; + display: flex; } .panel { + flex: 1; background:#6B0F9C; box-shadow:inset 0 0 0 5px rgba(255,255,255,0.1); color:white; @@ -41,6 +43,10 @@ font-size: 20px; background-size:cover; background-position:center; + justify-content: center; + align-items: center; + display: flex; + flex-direction: column; } @@ -54,6 +60,27 @@ margin:0; width: 100%; transition:transform 0.5s; + flex: 1; + display: flex; + align-items: center; + flex-direction: center; + justify-content: 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 { @@ -68,6 +95,7 @@ .panel.open { font-size:40px; + flex: 5; } .cta { @@ -107,7 +135,19 @@ diff --git a/06 - Type Ahead/index-START.html b/06 - Type Ahead/index-START.html index 1436886918..5334fb9165 100644 --- a/06 - Type Ahead/index-START.html +++ b/06 - Type Ahead/index-START.html @@ -17,6 +17,48 @@ diff --git a/07 - Array Cardio Day 2/index-START.html b/07 - Array Cardio Day 2/index-START.html index 206ec31aa0..c3aba7c046 100644 --- a/07 - Array Cardio Day 2/index-START.html +++ b/07 - Array Cardio Day 2/index-START.html @@ -25,17 +25,32 @@ ]; // Some and Every Checks + const year = (new Date()).getFullYear(); + function isNineteen(person) { + return person.year < (year - 19); + } + // Array.prototype.some() // is at least one person 19? + const isSomeoneNineteen = people.some(isNineteen); + console.log(isSomeoneNineteen); + // Array.prototype.every() // is everyone 19? + const isEveryoneNineteen = people.every(isNineteen); + console.log(isEveryoneNineteen); // 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 commentIndex = comments.findIndex(comment => comment.id === 823423); + // delete the comment with the ID of 823423 + comments.splice(commentIndex, 1); + console.log(comments); diff --git a/08 - Fun with HTML5 Canvas/index-START.html b/08 - Fun with HTML5 Canvas/index-START.html index 37c148df07..0b4830b673 100644 --- a/08 - Fun with HTML5 Canvas/index-START.html +++ b/08 - Fun with HTML5 Canvas/index-START.html @@ -7,6 +7,45 @@ diff --git a/17 - Sort Without Articles/index-START.html b/17 - Sort Without Articles/index-START.html index cfaf3e0440..ddd8c1232a 100644 --- a/17 - Sort Without Articles/index-START.html +++ b/17 - Sort Without Articles/index-START.html @@ -44,7 +44,21 @@ diff --git a/18 - Adding Up Times with Reduce/index-START.html b/18 - Adding Up Times with Reduce/index-START.html index 3eaee0f3ef..97a754432b 100644 --- a/18 - Adding Up Times with Reduce/index-START.html +++ b/18 - Adding Up Times with Reduce/index-START.html @@ -182,6 +182,25 @@ diff --git a/19 - Webcam Fun/index.html b/19 - Webcam Fun/index.html index d4ffc4dc2a..cb2d1b18a4 100755 --- a/19 - Webcam Fun/index.html +++ b/19 - Webcam Fun/index.html @@ -10,7 +10,7 @@
- +
diff --git a/19 - Webcam Fun/scripts.js b/19 - Webcam Fun/scripts.js index 00355f5a9c..ea9d8f7f2b 100644 --- a/19 - Webcam Fun/scripts.js +++ b/19 - Webcam Fun/scripts.js @@ -3,3 +3,89 @@ 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.src = window.URL.createObjectURL(localMediaStream); + video.play(); + }) + .catch(error => { + console.error("No devices :(", error); + }); +} + +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); + }, 16); +} + +function takePhoto() { + // played the sound + snap.currentTime = 0; + snap.play(); + + // take the data out of the canvas + const data = canvas.toDataURL('image/jpeg'); + const link = document.createElement('a'); + link.href = data; + link.setAttribute('download', 'handsome'); + link.innerHTML = `Handsome Man`; + strip.insertBefore(link, strip.firsChild); +} + +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(); + +video.addEventListener('canplay', paintToCanavas); diff --git a/20 - Speech Detection/index-START.html b/20 - Speech Detection/index-START.html index d3395cca35..9bde982288 100644 --- a/20 - Speech Detection/index-START.html +++ b/20 - Speech Detection/index-START.html @@ -10,9 +10,30 @@ diff --git a/21 - Geolocation/index-START.html b/21 - Geolocation/index-START.html index d794c144ba..c6b4c1eb70 100644 --- a/21 - Geolocation/index-START.html +++ b/21 - Geolocation/index-START.html @@ -57,6 +57,7 @@

/*Compass: https://thenounproject.com/search/?q=compass&i=592352*/ - diff --git a/23 - Speech Synthesis/index-START.html b/23 - Speech Synthesis/index-START.html index e890008d36..5483ba480a 100644 --- a/23 - Speech Synthesis/index-START.html +++ b/23 - Speech Synthesis/index-START.html @@ -35,6 +35,35 @@

The Voiceinator 5000

const options = document.querySelectorAll('[type="range"], [name="text"]'); const speakButton = document.querySelector('#speak'); const stopButton = document.querySelector('#stop'); + + function populateVoices() { + voices = this.getVoices(); + voicesDropdown.innerHTML = voices + .filter(voice => voice.lang.includes('en')) + .map(voice => ``) + .join(''); + } + + function toggle(startOver = true) { + speechSynthesis.cancel(); + if (startOver) speechSynthesis.speak(msg); + } + + function setVoice() { + msg.voice = voices.find(voice => voice.name === this.value); + toggle(); + } + + 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(false)); diff --git a/24 - Sticky Nav/index-START.html b/24 - Sticky Nav/index-START.html index e7bc67e9a5..6bcdfb0514 100644 --- a/24 - Sticky Nav/index-START.html +++ b/24 - Sticky Nav/index-START.html @@ -23,7 +23,6 @@

A story about getting lost.

-

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tempore tempora rerum, est autem cupiditate, corporis a qui libero ipsum delectus quidem dolor at nulla, adipisci veniam in reiciendis aut asperiores omnis blanditiis quod quas laborum nam! Fuga ad tempora in aspernatur pariatur fugit quibusdam dolores sunt esse magni, ut, dignissimos.

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tempore tempora rerum, est autem cupiditate, corporis a qui libero ipsum delectus quidem dolor at nulla, adipisci veniam in reiciendis aut asperiores omnis blanditiis quod quas laborum nam! Fuga ad tempora in aspernatur pariatur fugit quibusdam dolores sunt esse magni, ut, dignissimos.

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tempore tempora rerum, est autem cupiditate, corporis a qui libero ipsum delectus quidem dolor at nulla, adipisci veniam in reiciendis aut asperiores omnis blanditiis quod quas laborum nam! Fuga ad tempora in aspernatur pariatur fugit quibusdam dolores sunt esse magni, ut, dignissimos.

@@ -54,7 +53,20 @@

A story about getting lost.

diff --git a/24 - Sticky Nav/style-START.css b/24 - Sticky Nav/style-START.css index c6d59a31b3..3678c2500d 100644 --- a/24 - Sticky Nav/style-START.css +++ b/24 - Sticky Nav/style-START.css @@ -23,6 +23,10 @@ body { transition: transform 0.5s; } +body.fixed-nav .site-wrap { + transform: scale(1); +} + header { text-align: center; height:50vh; @@ -48,6 +52,11 @@ nav { z-index: 1; } +body.fixed-nav nav { + position: fixed; + box-shadow:0 5px 0 rgba(0,0,0,0.1); +} + nav ul { margin: 0; padding:0; @@ -76,6 +85,10 @@ li.logo a { color:black; } +.fixed-nav li.logo { + max-width:500px; +} + nav a { text-decoration: none; padding:20px; 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 98f5e070c4..fcf43a59ea 100644 --- a/25 - Event Capture, Propagation, Bubbling and Once/index-START.html +++ b/25 - Event Capture, Propagation, Bubbling and Once/index-START.html @@ -39,7 +39,23 @@ diff --git a/26 - Stripe Follow Along Nav/index-START.html b/26 - Stripe Follow Along Nav/index-START.html index 9780d0d1ac..d6ca91087a 100644 --- a/26 - Stripe Follow Along Nav/index-START.html +++ b/26 - Stripe Follow Along Nav/index-START.html @@ -134,8 +134,6 @@

Cool

opacity: 1; } - - .dropdownBackground { width:100px; height:100px; @@ -208,6 +206,43 @@

Cool

diff --git a/27 - Click and Drag/index-START.html b/27 - Click and Drag/index-START.html index b8609315f7..912f44579e 100644 --- a/27 - Click and Drag/index-START.html +++ b/27 - Click and Drag/index-START.html @@ -35,6 +35,37 @@ diff --git a/28 - Video Speed Controller/index-START.html b/28 - Video Speed Controller/index-START.html index c4cbd4259a..c9b81eb98f 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..f22405ddec 100644 --- a/29 - Countdown Timer/scripts-START.js +++ b/29 - Countdown Timer/scripts-START.js @@ -0,0 +1,56 @@ +let countdown; +const timerDisplay = document.querySelector('.display__time-left'); +const endTime = document.querySelector('.display__end-time'); +const buttons = document.querySelectorAll('[data-time]'); + +function tick(then) { + return function() { + const secondsLeft = Math.round((then - Date.now()) / 1000); + if(secondsLeft < 0) { + clearInterval(countdown); + return; + } + + displayTimeLeft(secondsLeft); + } +} + +function timer(seconds) { + clearInterval(countdown); + + const now = Date.now(); + const then = now + seconds * 1000; + displayTimeLeft(seconds); + displayEndTime(then); + + countdown = setInterval(tick(then), 1000); +} + +function displayTimeLeft(seconds) { + const minutes = Math.floor(seconds / 60); + const remainderSeconds = seconds % 60; + const display = `${minutes}:${remainderSeconds < 10 ? '0' : '' }${remainderSeconds}`; + document.title = display; + timerDisplay.textContent = display; +} + +function displayEndTime(timestamp) { + const end = new Date(timestamp); + const hour = end.getHours(); + const adjustedHour = hour > 12 ? hour - 12 : hour; + const minutes = end.getMinutes(); + endTime.textContent = `Be Back At ${adjustedHour}:${minutes < 10 ? '0' : ''}${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 mins = this.minutes.value; + timer(mins * 60); + this.reset(); +}); diff --git a/30 - Whack A Mole/index-START.html b/30 - Whack A Mole/index-START.html index 2014ff458c..f40f1e2b91 100644 --- a/30 - Whack A Mole/index-START.html +++ b/30 - Whack A Mole/index-START.html @@ -36,6 +36,51 @@

Whack-a-mole! 0

const holes = document.querySelectorAll('.hole'); const scoreBoard = document.querySelector('.score'); const moles = document.querySelectorAll('.mole'); + const roundCount = 10; + let currentRound; + let lastHole; + let score; + + function randomTime(max, min) { + return Math.round(Math.random() * (max - min) + min); + } + + function randomHole(holes) { + let idx; + while((idx = Math.floor(Math.random() * holes.length)) == lastHole); + lastHole = idx; + return holes[idx]; + } + + function peep() { + currentRound++; + const time = randomTime(400, 1000); + const hole = randomHole(holes); + hole.classList.add('up'); + setTimeout(() => { + hole.classList.remove('up'); + if (currentRound < roundCount) peep(); + }, time); + } + + function refreshScore() { + scoreBoard.innerText = score; + } + + function startGame() { + score = 0; + currentRound = 0; + refreshScore(); + peep(); + } + + function bonk() { + score++; + refreshScore(); + this.classList.remove('up'); + } + + moles.forEach(mole => mole.addEventListener('click', bonk));