From 5707bb4902298c494dfd9094b609bbc95e25fae1 Mon Sep 17 00:00:00 2001 From: Ryan Tvenge Date: Tue, 3 Jan 2017 15:39:19 -0800 Subject: [PATCH 01/28] Finished lesson 1 --- 01 - JavaScript Drum Kit/index-START.html | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/01 - JavaScript Drum Kit/index-START.html b/01 - JavaScript Drum Kit/index-START.html index 4070d32767..3974d14be3 100644 --- a/01 - JavaScript Drum Kit/index-START.html +++ b/01 - JavaScript Drum Kit/index-START.html @@ -58,7 +58,24 @@ From 879997e472946275b861002a77cb5667cac6c459 Mon Sep 17 00:00:00 2001 From: Ryan Tvenge Date: Thu, 5 Jan 2017 14:11:04 -0800 Subject: [PATCH 02/28] lesson 2 done --- 02 - JS + CSS Clock/index-START.html | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/02 - JS + CSS Clock/index-START.html b/02 - JS + CSS Clock/index-START.html index 2712384201..eca7247e09 100644 --- a/02 - JS + CSS Clock/index-START.html +++ b/02 - JS + CSS Clock/index-START.html @@ -61,13 +61,35 @@ background:black; position: absolute; top:50%; + transform-origin: 100%; + transform: rotate(90deg); + transition: all 0.05s; + transition-timing-function: cubic-bezier(0.42, 0, 0.4, 2.12); } From fc44b64a3f4c216be87c9a558795f0c30f53020b Mon Sep 17 00:00:00 2001 From: Ryan Tvenge Date: Fri, 6 Jan 2017 12:05:12 -0800 Subject: [PATCH 03/28] finishing #3 --- 03 - CSS Variables/index-START.html | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/03 - CSS Variables/index-START.html b/03 - CSS Variables/index-START.html index ca2b59d077..86b46f4821 100644 --- a/03 - CSS Variables/index-START.html +++ b/03 - CSS Variables/index-START.html @@ -22,6 +22,22 @@

Update CSS Variables with JS

From e0b773d5b13323872dbcc8eed04d5ff937b0a6c6 Mon Sep 17 00:00:00 2001 From: Ryan Tvenge Date: Fri, 6 Jan 2017 14:24:21 -0800 Subject: [PATCH 04/28] finishing 4 --- 04 - Array Cardio Day 1/index-START.html | 39 ++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/04 - Array Cardio Day 1/index-START.html b/04 - Array Cardio Day 1/index-START.html index eec0ffc31d..72978cadef 100644 --- a/04 - Array Cardio Day 1/index-START.html +++ b/04 - Array Cardio Day 1/index-START.html @@ -31,29 +31,68 @@ // Array.prototype.filter() // 1. Filter the list of inventors for those who were born in the 1500's + const fifteen = inventors.filter(inventor => 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 fullNames = inventors.map(inventor => `${inventor.first} ${inventor.last}`); + console.log(fullNames); // Array.prototype.sort() // 3. Sort the inventors by birthdate, oldest to youngest + const ordered = inventors.sort((a, b) => (a.year > b.year) ? 1 : -1); + + console.table(ordered); // Array.prototype.reduce() // 4. How many years did all the inventors live? + const totalYears = inventors.reduce((total, inventor) => { + return total + (inventor.passed - inventor.year); + }, 0); + + console.log(totalYears); // 5. Sort the inventors by years lived + const oldest = inventors.sort(function (a, b) { + const lastGuy = a.passed - a.year; + const nextGuy = b.passed - b.year; + return lastGuy > nextGuy ? -1 : 1; + }); + console.table(oldest); // 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 category = document.querySelector('.mw-category'); + // const links = Array.from(category.querySelectorAll('a')); + // const de = links + // .map(link => link.textContent) + // .filter(streetName => streetName.includes('de')); // 7. sort Exercise // Sort the people alphabetically by last name + const alpha = people.sort((lastOne, nextOne) => { + const [aLast, aFirst] = lastOne.split(', '); + const [bLast, bFirst] = nextOne.split(', '); + return aLast > bLast ? -1 : 1; + }); + console.log(alpha); // 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 transportation = data.reduce(function (obj, item) { + if (!obj[item]) { + obj[item] = 0; + } + obj[item]++; + return obj; + }, {}); + + console.log(transportation); + From 7285c0f0242c0d5371a2848e22a64ea226ee23e9 Mon Sep 17 00:00:00 2001 From: Ryan Tvenge Date: Mon, 9 Jan 2017 08:42:25 -0800 Subject: [PATCH 05/28] finished 5 --- 05 - Flex Panel Gallery/index-START.html | 42 ++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/05 - Flex Panel Gallery/index-START.html b/05 - Flex Panel Gallery/index-START.html index e1d643ad5c..45df720180 100644 --- a/05 - Flex Panel Gallery/index-START.html +++ b/05 - Flex Panel Gallery/index-START.html @@ -24,6 +24,7 @@ .panels { min-height:100vh; overflow: hidden; + display: flex; } .panel { @@ -41,6 +42,11 @@ font-size: 20px; background-size:cover; background-position:center; + flex: 1; + justify-content: center; + align-items: center; + display: flex; + flex-direction: column; } @@ -54,6 +60,23 @@ 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 { @@ -66,6 +89,11 @@ font-size: 4em; } + .panel.open { + flex: 5; + font-size: 40px; + } + .panel.open { font-size:40px; } @@ -107,7 +135,21 @@ From 4cf93af930ba21e7145db3d6414151b997358a58 Mon Sep 17 00:00:00 2001 From: Ryan Tvenge Date: Mon, 9 Jan 2017 09:04:18 -0800 Subject: [PATCH 06/28] finshing 6 --- 06 - Type Ahead/index-START.html | 40 ++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/06 - Type Ahead/index-START.html b/06 - Type Ahead/index-START.html index 1436886918..448c134a13 100644 --- a/06 - Type Ahead/index-START.html +++ b/06 - Type Ahead/index-START.html @@ -17,6 +17,46 @@ From 35e91172346988ebb97d4e3be899af90dca753f3 Mon Sep 17 00:00:00 2001 From: Ryan Tvenge Date: Mon, 9 Jan 2017 09:15:44 -0800 Subject: [PATCH 07/28] finishing 7 --- 07 - Array Cardio Day 2/index-START.html | 33 ++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/07 - Array Cardio Day 2/index-START.html b/07 - Array Cardio Day 2/index-START.html index 969566ff78..81f249e822 100644 --- a/07 - Array Cardio Day 2/index-START.html +++ b/07 - Array Cardio Day 2/index-START.html @@ -26,15 +26,48 @@ // Some and Every Checks // Array.prototype.some() // is at least one person 19 or older? + // const isAdult = people.some(function (person) { + // const currentYear = (new Date()).getFullYear(); + // if (currentYear - person.year >= 19) { + // return true; + // } + // }); + const isAdult = people.some(person => { + const currentYear = (new Date()).getFullYear(); + return currentYear - person.year >= 19; + }); + console.log({isAdult}); // Array.prototype.every() // is everyone 19 or older? + const allAdults = people.every(person => { + const currentYear = (new Date()).getFullYear(); + return currentYear - person.year >= 19; + }); + console.log({allAdults}); // 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(function (comment) { + // if (comment.id === 823423) { + // return true; + // } + // }); + 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); + console.log(index); + + const newComments = [ + ...comments.slice(0, index), + ...comments.slice(index + 1) + ] + + console.table(comments); + console.table(newComments); From 2e9af6b6e635ed374b18373650835ac42514fbe6 Mon Sep 17 00:00:00 2001 From: Ryan Tvenge Date: Tue, 10 Jan 2017 08:58:16 -0800 Subject: [PATCH 08/28] finished 8 --- 08 - Fun with HTML5 Canvas/index-START.html | 52 +++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/08 - Fun with HTML5 Canvas/index-START.html b/08 - Fun with HTML5 Canvas/index-START.html index 37c148df07..465319ea8c 100644 --- a/08 - Fun with HTML5 Canvas/index-START.html +++ b/08 - Fun with HTML5 Canvas/index-START.html @@ -7,6 +7,58 @@ From c03dabb04106fba3a03518d0abcd718683e94563 Mon Sep 17 00:00:00 2001 From: Ryan Tvenge Date: Thu, 19 Jan 2017 14:40:59 -0800 Subject: [PATCH 15/28] 17 --- 17 - Sort Without Articles/index-START.html | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/17 - Sort Without Articles/index-START.html b/17 - Sort Without Articles/index-START.html index cfaf3e0440..fc57b3098d 100644 --- a/17 - Sort Without Articles/index-START.html +++ b/17 - Sort Without Articles/index-START.html @@ -45,6 +45,16 @@ From b4331f760a56bdc1ca06645033006a28a484228b Mon Sep 17 00:00:00 2001 From: Ryan Tvenge Date: Mon, 23 Jan 2017 10:02:40 -0800 Subject: [PATCH 16/28] 18 --- .../index-START.html | 18 ++++++++++++++++++ 1 file changed, 18 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..f3d2bb7380 100644 --- a/18 - Adding Up Times with Reduce/index-START.html +++ b/18 - Adding Up Times with Reduce/index-START.html @@ -180,8 +180,26 @@
  • Video 58
  • + From 6a553530bcc356aa76ca7c0f8f84addd57f7d234 Mon Sep 17 00:00:00 2001 From: Ryan Tvenge Date: Mon, 23 Jan 2017 10:55:14 -0800 Subject: [PATCH 17/28] 19 --- 19 - Webcam Fun/index.html | 4 +- 19 - Webcam Fun/scripts.js | 92 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 2 deletions(-) diff --git a/19 - Webcam Fun/index.html b/19 - Webcam Fun/index.html index d4ffc4dc2a..a2c66ca55a 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..267fe799f4 100644 --- a/19 - Webcam Fun/scripts.js +++ b/19 - Webcam Fun/scripts.js @@ -3,3 +3,95 @@ 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 => { + console.log(localMediaStream); + video.src = window.URL.createObjectURL(localMediaStream); + video.play(); + }) + .catch(err => { + console.error(`OH NO!!!`, err); + }); +} + +function paintToCanavas () { + const width = video.videoWidth; + const height = video.videoHeight; + canvas.width = width; + canvas.height = height; + + return setInterval(() => { + ctx.drawImage(video, 0, 0, width, height); + let pixels = ctx.getImageData(0, 0, width, height); + // pixels = redEffect(pixels); + // pixels = rgbSplit(pixels); + // ctx.globalAlpha = 0.4; + pixels = greenScreen(pixels); + ctx.putImageData(pixels, 0, 0); + }, 16); +} + +function takePhoto () { + // already played 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', 'handsome'); + link.innerHTML = `Handsome Man`; + 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] + 100; + pixels.data[i + 1] = pixels.data[i + 1] - 50; + pixels.data[i + 2] = pixels.data[i + 2] + 0.5; + } + return pixels; +} + +function rgbSplit (pixels) { + for (let i = 0; i < pixels.data.length; i+=4) { + pixels.data[i - 150] = pixels.data[i + 0]; + pixels.data[i + 100] = pixels.data[i + 1]; + pixels.data[i - 150] = pixels.data[i + 2]; + } + 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 8041abe27bac907e37a1a870016c09e962f18b4b Mon Sep 17 00:00:00 2001 From: Ryan Tvenge Date: Mon, 23 Jan 2017 11:36:35 -0800 Subject: [PATCH 18/28] 20 --- 20 - Speech Detection/index-START.html | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/20 - Speech Detection/index-START.html b/20 - Speech Detection/index-START.html index d3395cca35..9444f61c49 100644 --- a/20 - Speech Detection/index-START.html +++ b/20 - Speech Detection/index-START.html @@ -12,6 +12,29 @@ From 985ebdcc1d357981e3f7677bba9cf59e1b5f7e81 Mon Sep 17 00:00:00 2001 From: Ryan Tvenge Date: Mon, 23 Jan 2017 11:59:05 -0800 Subject: [PATCH 19/28] 21 --- 21 - Geolocation/index-START.html | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/21 - Geolocation/index-START.html b/21 - Geolocation/index-START.html index a1b981b1cd..bb06942f63 100644 --- a/21 - Geolocation/index-START.html +++ b/21 - Geolocation/index-START.html @@ -57,6 +57,17 @@

    /*Compass: https://thenounproject.com/search/?q=compass&i=592352*/ From 1b9dc68cc21cb065633fbe41ed08025ead90977d Mon Sep 17 00:00:00 2001 From: Ryan Tvenge Date: Tue, 24 Jan 2017 07:57:33 -0800 Subject: [PATCH 20/28] 22 --- .../index-START.html | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/22 - Follow Along Link Highlighter/index-START.html b/22 - Follow Along Link Highlighter/index-START.html index 8476112b5e..f6fb2a089c 100644 --- a/22 - Follow Along Link Highlighter/index-START.html +++ b/22 - Follow Along Link Highlighter/index-START.html @@ -27,7 +27,25 @@ - From 262d8ff827d35d7485364d4bd785eefd87afd1e7 Mon Sep 17 00:00:00 2001 From: Ryan Tvenge Date: Thu, 26 Jan 2017 15:11:47 -0800 Subject: [PATCH 21/28] 23 --- 23 - Speech Synthesis/index-START.html | 35 ++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/23 - Speech Synthesis/index-START.html b/23 - Speech Synthesis/index-START.html index e890008d36..f16a595e16 100644 --- a/23 - Speech Synthesis/index-START.html +++ b/23 - Speech Synthesis/index-START.html @@ -35,6 +35,41 @@

    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(); + voicesDropdown.innerHTML = voices + .filter(voice => voice.lang.includes('en')) + .map(voice => ``) + .join(''); + } + + function setVoice () { + console.log(this.value); + msg.voice = voices.find(voice => voice.name === this.value); + toggle(); + } + + function toggle (startOver = true) { + speechSynthesis.cancel(); + if (startOver) { + speechSynthesis.speak(msg); + } + } + + function setOption () { + console.log(this.name, this.value); + 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 3b2bc9af0de61b244495802c56ae677ca9062c37 Mon Sep 17 00:00:00 2001 From: Ryan Tvenge Date: Fri, 27 Jan 2017 11:04:48 -0800 Subject: [PATCH 22/28] 24 --- 24 - Sticky Nav/index-START.html | 14 ++++++++++++++ 24 - Sticky Nav/style-START.css | 13 +++++++++++++ 2 files changed, 27 insertions(+) diff --git a/24 - Sticky Nav/index-START.html b/24 - Sticky Nav/index-START.html index e7bc67e9a5..242e73db75 100644 --- a/24 - Sticky Nav/index-START.html +++ b/24 - Sticky Nav/index-START.html @@ -54,6 +54,20 @@

    A story about getting lost.

    diff --git a/24 - Sticky Nav/style-START.css b/24 - Sticky Nav/style-START.css index c6d59a31b3..a3db8925c4 100644 --- a/24 - Sticky Nav/style-START.css +++ b/24 - Sticky Nav/style-START.css @@ -23,6 +23,10 @@ body { transition: transform 0.5s; } +.fixed-nav .site-wrap { + transform: scale(1); +} + header { text-align: center; height:50vh; @@ -48,6 +52,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; @@ -72,6 +81,10 @@ li.logo { font-size: 30px; } +.fixed-nav li.logo { + max-width: 500px; +} + li.logo a { color:black; } From 248a8663047c27005a7dbc967c4cfee8cfca7454 Mon Sep 17 00:00:00 2001 From: Ryan Tvenge Date: Fri, 27 Jan 2017 11:04:52 -0800 Subject: [PATCH 23/28] 25 --- .../index-START.html | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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..c2f175be3a 100644 --- a/25 - Event Capture, Propagation, Bubbling and Once/index-START.html +++ b/25 - Event Capture, Propagation, Bubbling and Once/index-START.html @@ -37,8 +37,18 @@ } - From ecf256956127a862b55087d3c91b28e1c7c85758 Mon Sep 17 00:00:00 2001 From: Ryan Tvenge Date: Sat, 28 Jan 2017 19:58:34 -0800 Subject: [PATCH 24/28] 26 --- 26 - Stripe Follow Along Nav/index-START.html | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/26 - Stripe Follow Along Nav/index-START.html b/26 - Stripe Follow Along Nav/index-START.html index 9780d0d1ac..8c7c2d7602 100644 --- a/26 - Stripe Follow Along Nav/index-START.html +++ b/26 - Stripe Follow Along Nav/index-START.html @@ -134,6 +134,14 @@

    Cool

    opacity: 1; } + .trigger-enter .dropdown { + display: block; + } + + .trigger-enter-active .dropdown { + opacity: 1; + } + .dropdownBackground { @@ -208,6 +216,47 @@

    Cool

    From d1cfa220fa5dedd12a1dc50fc8f046e6bc881224 Mon Sep 17 00:00:00 2001 From: Ryan Tvenge Date: Sat, 28 Jan 2017 20:13:08 -0800 Subject: [PATCH 25/28] 27 --- 27 - Click and Drag/index-START.html | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/27 - Click and Drag/index-START.html b/27 - Click and Drag/index-START.html index b8609315f7..82afac2457 100644 --- a/27 - Click and Drag/index-START.html +++ b/27 - Click and Drag/index-START.html @@ -35,6 +35,33 @@ From e1857579b6893dbf51a302525b77bed911163f5e Mon Sep 17 00:00:00 2001 From: Ryan Tvenge Date: Sun, 29 Jan 2017 21:18:24 -0800 Subject: [PATCH 26/28] 28; --- 28 - Video Speed Controller/index-START.html | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/28 - Video Speed Controller/index-START.html b/28 - Video Speed Controller/index-START.html index c4cbd4259a..65f32b8cd9 100644 --- a/28 - Video Speed Controller/index-START.html +++ b/28 - Video Speed Controller/index-START.html @@ -15,6 +15,23 @@ From 2e16eb5d2171b88962fd2b580ce8a17a20d544cc Mon Sep 17 00:00:00 2001 From: Ryan Tvenge Date: Tue, 31 Jan 2017 09:40:43 -0800 Subject: [PATCH 27/28] 29 --- 29 - Countdown Timer/scripts-START.js | 50 +++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/29 - Countdown Timer/scripts-START.js b/29 - Countdown Timer/scripts-START.js index e69de29bb2..451f8b736e 100644 --- a/29 - Countdown Timer/scripts-START.js +++ b/29 - Countdown Timer/scripts-START.js @@ -0,0 +1,50 @@ +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) { + clearInterval(countdown); + const now = Date.now(); + const then = now + seconds * 1000; + displayTimeLeft(seconds); + displayEndTime(then); + + countdown = setInterval(() => { + const secondsLeft = Math.round((then - Date.now()) / 1000); + // check if we should stop it + 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}:${remainderSeconds < 10 ? '0' : '' }${remainderSeconds}`; + timerDisplay.textContent = display; + document.title = display; +} + +function displayEndTime (timestamp) { + const end = new Date(timestamp); + const hour = end.getHours(); + const minutes = end.getMinutes(); + endTime.textContent = `Be Back at ${hour > 12 ? hour - 12 : hour}:${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(); +}); From 6fcfdb12cc1b0132e384c4d832d470c208bf1a78 Mon Sep 17 00:00:00 2001 From: Ryan Tvenge Date: Wed, 1 Feb 2017 09:34:18 -0800 Subject: [PATCH 28/28] 30 --- 30 - Whack A Mole/index-START.html | 45 ++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/30 - Whack A Mole/index-START.html b/30 - Whack A Mole/index-START.html index 2014ff458c..52aa954d07 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'); + let lastHole; + let timeUp = false; + let score = 0; + + function randomTime (min, max) { + return Math.round(Math.random() * (max - min) + min); + } + + function randomHole (holes) { + const idx = Math.floor(Math.random() * holes.length); + const hole = holes[idx]; + 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; // cheeting + score++; + this.classList.remove('up'); + scoreBoard.textContent = score; + } + + moles.forEach(mole => mole.addEventListener('click', bonk));