From 3441e3f2aa3e1846093607800d211cc885d3dd4e Mon Sep 17 00:00:00 2001 From: Brian Carrigan Date: Sat, 17 Dec 2016 13:51:17 -0500 Subject: [PATCH 01/30] Finish first and second days. --- 01 - JavaScript Drum Kit/index-START.html | 17 ++++++++++++++++ 02 - JS + CSS Clock/index-START.html | 24 +++++++++++++++++++++++ 2 files changed, 41 insertions(+) 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); } From b6d04389e8d72580d41dc296f16e240fe877d19d Mon Sep 17 00:00:00 2001 From: Brian Carrigan Date: Sun, 18 Dec 2016 14:44:30 -0500 Subject: [PATCH 02/30] Finished day 3. --- 03 - CSS Variables/index-START.html | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) 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

From 2eb7ee3a989efeed20b5e54b3e47120fd89c549b Mon Sep 17 00:00:00 2001 From: Brian Carrigan Date: Mon, 19 Dec 2016 17:23:46 -0500 Subject: [PATCH 03/30] Day 4 - Complete. --- 04 - Array Cardio Day 1/index-START.html | 25 ++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) 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); From ad53f574779cc57c3db0337f18988b84ef23c239 Mon Sep 17 00:00:00 2001 From: Brian Carrigan Date: Tue, 20 Dec 2016 08:20:46 -0500 Subject: [PATCH 04/30] Finish #5 at 30k feet. --- 05 - Flex Panel Gallery/index-START.html | 40 ++++++++++++++++++++++++ 1 file changed, 40 insertions(+) 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 @@ From f0efca8fe64ca119f324575587e59774b7495963 Mon Sep 17 00:00:00 2001 From: Brian Carrigan Date: Wed, 21 Dec 2016 20:51:42 -0500 Subject: [PATCH 05/30] Finish day 6 --- 06 - Type Ahead/index-START.html | 42 ++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) 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 @@ From 4c72698b42f0a26dd89ee914597c4e64ce55bd7a Mon Sep 17 00:00:00 2001 From: Brian Carrigan Date: Thu, 22 Dec 2016 08:43:52 -0500 Subject: [PATCH 06/30] Finished day 7. --- 07 - Array Cardio Day 2/index-START.html | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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); From 72259a37aa858b74c1bf511c633887363b087026 Mon Sep 17 00:00:00 2001 From: Brian Carrigan Date: Fri, 23 Dec 2016 09:31:14 -0500 Subject: [PATCH 07/30] Finish day 8 --- 08 - Fun with HTML5 Canvas/index-START.html | 39 +++++++++++++++++++++ 1 file changed, 39 insertions(+) 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 @@ From 9dbd6f7d8266f016bcb591e948f38fbc9b53c490 Mon Sep 17 00:00:00 2001 From: Brian Carrigan Date: Sun, 1 Jan 2017 19:02:08 -0500 Subject: [PATCH 16/30] Finish day 17. --- 17 - Sort Without Articles/index-START.html | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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 @@ From 98e6b4376c2897a05f1cb5f98ba301a494464bec Mon Sep 17 00:00:00 2001 From: Brian Carrigan Date: Tue, 3 Jan 2017 08:48:58 -0500 Subject: [PATCH 17/30] Finish day 18 --- .../index-START.html | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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 @@ From 8871f871d1488e615915d553786eb7676c5b9962 Mon Sep 17 00:00:00 2001 From: Brian Carrigan Date: Tue, 3 Jan 2017 21:54:10 -0500 Subject: [PATCH 18/30] Catchup: Day 19 --- 19 - Webcam Fun/index.html | 4 +- 19 - Webcam Fun/scripts.js | 86 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 2 deletions(-) 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); From c0bc2f37e5a8c391393a5724f563f8675a931c2e Mon Sep 17 00:00:00 2001 From: Brian Carrigan Date: Tue, 3 Jan 2017 22:15:41 -0500 Subject: [PATCH 19/30] Finish day 20 on time. --- 20 - Speech Detection/index-START.html | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/20 - Speech Detection/index-START.html b/20 - Speech Detection/index-START.html index d3395cca35..ddaa4a4e8a 100644 --- a/20 - Speech Detection/index-START.html +++ b/20 - Speech Detection/index-START.html @@ -10,9 +10,20 @@ From 497529d19174198aa56512f12bdf94d7bd1c8689 Mon Sep 17 00:00:00 2001 From: Brian Carrigan Date: Wed, 4 Jan 2017 19:20:32 -0500 Subject: [PATCH 20/30] Forgot to commit the rest yesterday. --- 20 - Speech Detection/index-START.html | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/20 - Speech Detection/index-START.html b/20 - Speech Detection/index-START.html index ddaa4a4e8a..9bde982288 100644 --- a/20 - Speech Detection/index-START.html +++ b/20 - Speech Detection/index-START.html @@ -20,9 +20,19 @@ words.appendChild(p); recognition.addEventListener('result', e => { - console.log(e); + const transcript = Array.from(e.results) + .map(result => result[0].transcript) + .join(''); + + p.textContent = transcript; + if (e.results[0].isFinal) { + p = document.createElement('p'); + words.appendChild(p); + } }); + recognition.addEventListener('end', recognition.start); + recognition.start(); From fae96f32512835ffc6672df7287576ee42cee362 Mon Sep 17 00:00:00 2001 From: Brian Carrigan Date: Wed, 4 Jan 2017 19:20:39 -0500 Subject: [PATCH 21/30] Finished day 21. --- 21 - Geolocation/index-START.html | 1 + 1 file changed, 1 insertion(+) 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*/ - From 5c92f616f434a404f6b06c16940c6c1762ae11d8 Mon Sep 17 00:00:00 2001 From: Brian Carrigan Date: Tue, 10 Jan 2017 21:22:25 -0500 Subject: [PATCH 23/30] Finish day 23 --- 23 - Speech Synthesis/index-START.html | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) 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)); From 015e19c244c7fb7f7e2140c1a434540d8839eb17 Mon Sep 17 00:00:00 2001 From: Brian Carrigan Date: Tue, 10 Jan 2017 21:37:43 -0500 Subject: [PATCH 24/30] Finish day 24. --- 24 - Sticky Nav/index-START.html | 16 ++++++++++++++-- 24 - Sticky Nav/style-START.css | 13 +++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) 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; From 505a14692bf919817fb77e87bcadc9f0e7550657 Mon Sep 17 00:00:00 2001 From: Brian Carrigan Date: Tue, 10 Jan 2017 22:15:30 -0500 Subject: [PATCH 25/30] Also do day 25. --- .../index-START.html | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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 @@ From c7e0ad41ec572fad3447664236f87ab1665773bd Mon Sep 17 00:00:00 2001 From: Brian Carrigan Date: Wed, 11 Jan 2017 08:58:06 -0500 Subject: [PATCH 26/30] Finish day 26. --- 26 - Stripe Follow Along Nav/index-START.html | 39 ++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-) 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

From e704f084bdb1ce1a093b352a6bee25e701976e47 Mon Sep 17 00:00:00 2001 From: Brian Carrigan Date: Thu, 26 Jan 2017 09:06:42 -0500 Subject: [PATCH 27/30] Finish day 27. --- 27 - Click and Drag/index-START.html | 31 ++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) 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 @@ From a3a02b0a25b20f3ebea8ad29d83efd08738f0612 Mon Sep 17 00:00:00 2001 From: Brian Carrigan Date: Sat, 28 Jan 2017 13:40:31 -0500 Subject: [PATCH 28/30] Finish day 28. --- 28 - Video Speed Controller/index-START.html | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/28 - Video Speed Controller/index-START.html b/28 - Video Speed Controller/index-START.html index c4cbd4259a..932b19e4e9 100644 --- a/28 - Video Speed Controller/index-START.html +++ b/28 - Video Speed Controller/index-START.html @@ -15,6 +15,22 @@ From 5f0f6b4c4164e99640a8d44715b678ad7dc92f8a Mon Sep 17 00:00:00 2001 From: Brian Carrigan Date: Tue, 31 Jan 2017 08:37:57 -0500 Subject: [PATCH 29/30] Finish day 28. --- 28 - Video Speed Controller/index-START.html | 1 + 1 file changed, 1 insertion(+) diff --git a/28 - Video Speed Controller/index-START.html b/28 - Video Speed Controller/index-START.html index 932b19e4e9..c9b81eb98f 100644 --- a/28 - Video Speed Controller/index-START.html +++ b/28 - Video Speed Controller/index-START.html @@ -29,6 +29,7 @@ bar.style.height = height; bar.textContent = playbackRate.toFixed(1) + "x"; + video.playbackRate = playbackRate; }); From 1c762d78b765c090de061df1a83b1a9dec227cec Mon Sep 17 00:00:00 2001 From: Brian Carrigan Date: Tue, 31 Jan 2017 14:22:18 -0800 Subject: [PATCH 30/30] Finish the Javascript 30 :raised_hands: --- 29 - Countdown Timer/scripts-START.js | 56 +++++++++++++++++++++++++++ 30 - Whack A Mole/index-START.html | 45 +++++++++++++++++++++ 2 files changed, 101 insertions(+) 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));