diff --git a/01 - JavaScript Drum Kit/index-START.html b/01 - JavaScript Drum Kit/index-START.html index 4070d32767..28a44891e2 100644 --- a/01 - JavaScript Drum Kit/index-START.html +++ b/01 - JavaScript Drum Kit/index-START.html @@ -58,7 +58,46 @@ diff --git a/01 - JavaScript Drum Kit/style.css b/01 - JavaScript Drum Kit/style.css index 075578c930..bd3c7f3483 100644 --- a/01 - JavaScript Drum Kit/style.css +++ b/01 - JavaScript Drum Kit/style.css @@ -29,6 +29,12 @@ body,html { color: white; background: rgba(0,0,0,0.4); text-shadow: 0 0 .5rem black; + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + -o-user-select: none; + user-select: none; + } .playing { diff --git a/02 - JS and CSS Clock/index-START.html b/02 - JS and CSS Clock/index-START.html index ee7eaefb1f..6e16ce9ff5 100644 --- a/02 - JS and CSS Clock/index-START.html +++ b/02 - JS and CSS Clock/index-START.html @@ -18,9 +18,9 @@ diff --git a/03 - CSS Variables/index-START.html b/03 - CSS Variables/index-START.html index 8a4f0d556e..c757d5a01d 100644 --- a/03 - CSS Variables/index-START.html +++ b/03 - CSS Variables/index-START.html @@ -5,22 +5,70 @@ Scoped CSS Variables and JS -

Update CSS Variables with JS

+
+
+

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 eec0ffc31d..7fbf92797d 100644 --- a/04 - Array Cardio Day 1/index-START.html +++ b/04 - Array Cardio Day 1/index-START.html @@ -27,33 +27,67 @@ { first: 'Hanna', last: 'HammarstrΓΆm', year: 1829, passed: 1909 } ]; - const people = ['Beck, Glenn', 'Becker, Carl', 'Beckett, Samuel', 'Beddoes, Mick', 'Beecher, Henry', 'Beethoven, Ludwig', 'Begin, Menachem', 'Belloc, Hilaire', 'Bellow, Saul', 'Benchley, Robert', 'Benenson, Peter', 'Ben-Gurion, David', 'Benjamin, Walter', 'Benn, Tony', 'Bennington, Chester', 'Benson, Leana', 'Bent, Silas', 'Bentsen, Lloyd', 'Berger, Ric', 'Bergman, Ingmar', 'Berio, Luciano', 'Berle, Milton', 'Berlin, Irving', 'Berne, Eric', 'Bernhard, Sandra', 'Berra, Yogi', 'Berry, Halle', 'Berry, Wendell', 'Bethea, Erin', 'Bevan, Aneurin', 'Bevel, Ken', 'Biden, Joseph', 'Bierce, Ambrose', 'Biko, Steve', 'Billings, Josh', 'Biondo, Frank', 'Birrell, Augustine', 'Black, Elk', 'Blair, Robert', 'Blair, Tony', 'Blake, William']; + const people = ['Beck, Glenn', 'Becker, Carl', 'Beckett, Samuel', 'Beddoes, Mick', 'Beecher, Henry', 'Beethoven, Ludwig', 'Begin, Menachem', 'Belloc, Hilaire', 'Bellow, Saul', 'Benchley, Robert', 'Benenson, Peter', 'Ben-Gurion, David', 'Benjamin, Walter', 'Benn, Tony', 'Bennington, Chester', 'Benson, Leana', 'Bent, Silas', 'Bentsen, Lloyd', 'Berger, Ric', 'Bergman, Ingmar', 'Berio, Luciano', 'Berle, Milton', 'Berlin, Irving', 'Berne, Eric', 'Bernhard, Sandra', 'Berra, Yogi', 'Berry, Halle', 'Berry, Wendell', 'Bethea, Erin', 'Bevan, Aneurin', 'Bevel, Ken', 'Biden, Joseph', 'Bierce, Ambrose', 'Biko, Steve', 'Billings, Josh', 'Biondo, Frank', 'Birrell, Augustine', 'Black, Elk', 'Blair, Robert', 'Blair, Tony', 'Blake, William', 'Cartright, Lance', 'Arlington, Stacey']; // 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 fullName = inventors.map(inventor => inventor.first + ' ' + inventor.last); + console.log(fullName); // Array.prototype.sort() // 3. Sort the inventors by birthdate, oldest to youngest + const inventorAge = inventors.sort((a, b) => a.year > b.year ? 1: -1); + console.table(inventorAge); // Array.prototype.reduce() // 4. How many years did all the inventors live? + const inventorsLived = inventors.reduce((total, inventor) => { + return total + (inventor.passed - inventor.year);}, 0); + console.log(inventorsLived); // 5. Sort the inventors by years lived + const ageAtDeath = inventors.sort((a, b) => (a.passed - a.year) < (b.passed - b.year) ? 1 : -1); + console.table(ageAtDeath); // 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 sortedNames = people.sort((a, b) => { + const [aLast, aFirst] = a.split(', '); + const [bLast, bFirst] = b.split(', '); + return aLast > bLast ? 1 : -1; + }); + console.log(sortedNames); + console.log("test"); // 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); + diff --git a/05 - Flex Panel Gallery/index-START.html b/05 - Flex Panel Gallery/index-START.html index c6509bed02..a33ca9daa9 100644 --- a/05 - Flex Panel Gallery/index-START.html +++ b/05 - Flex Panel Gallery/index-START.html @@ -24,9 +24,15 @@ .panels { min-height:100vh; overflow: hidden; + display: flex; } .panel { + display: flex; + flex-direction: column; + flex: 1; + justify-content: center; + align-items: center; background:#6B0F9C; box-shadow:inset 0 0 0 5px rgba(255,255,255,0.1); color:white; @@ -54,8 +60,17 @@ 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 { text-transform: uppercase; font-family: 'Amatic SC', cursive; @@ -67,6 +82,7 @@ } .panel.open { + flex: 5; font-size:40px; } @@ -102,7 +118,20 @@ diff --git a/06 - Type Ahead/index-START.html b/06 - Type Ahead/index-START.html index 1436886918..e95d7c8956 100644 --- a/06 - Type Ahead/index-START.html +++ b/06 - Type Ahead/index-START.html @@ -15,7 +15,46 @@ diff --git a/07 - Array Cardio Day 2/index-START.html b/07 - Array Cardio Day 2/index-START.html index 969566ff78..0bb1b3bcf2 100644 --- a/07 - Array Cardio Day 2/index-START.html +++ b/07 - Array Cardio Day 2/index-START.html @@ -26,15 +26,35 @@ // Some and Every Checks // Array.prototype.some() // is at least one person 19 or older? + 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(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); + + comments.splice(index, 1); diff --git a/08 - Fun with HTML5 Canvas/index-START.html b/08 - Fun with HTML5 Canvas/index-START.html index 37c148df07..6e295fbd82 100644 --- a/08 - Fun with HTML5 Canvas/index-START.html +++ b/08 - Fun with HTML5 Canvas/index-START.html @@ -7,6 +7,58 @@ diff --git a/14 - JavaScript References VS Copying/index-START.html b/14 - JavaScript References VS Copying/index-START.html index 73cd5ae5a5..d7322028a5 100644 --- a/14 - JavaScript References VS Copying/index-START.html +++ b/14 - JavaScript References VS Copying/index-START.html @@ -8,15 +8,31 @@ diff --git a/15 - LocalStorage/index-START.html b/15 - LocalStorage/index-START.html index d444f1d68b..db6ea74068 100644 --- a/15 - LocalStorage/index-START.html +++ b/15 - LocalStorage/index-START.html @@ -21,14 +21,78 @@

LOCAL TAPAS

- +
+
+ + +
diff --git a/15 - LocalStorage/style.css b/15 - LocalStorage/style.css index ea5bab179c..67930be36e 100644 --- a/15 - LocalStorage/style.css +++ b/15 - LocalStorage/style.css @@ -71,7 +71,8 @@ margin-top: 20px; } - .add-items input { + .add-items input, + button { padding:10px; outline:0; border:1px solid rgba(0,0,0,0.1); diff --git a/16 - Mouse Move Shadow/index-start.html b/16 - Mouse Move Shadow/index-start.html index 543cb51eab..2f60800058 100644 --- a/16 - Mouse Move Shadow/index-start.html +++ b/16 - Mouse Move Shadow/index-start.html @@ -7,13 +7,14 @@
-

πŸ”₯WOAH!

+

Shadow!

diff --git a/17 - Sort Without Articles/index-START.html b/17 - Sort Without Articles/index-START.html index 9bbd250a9b..c69993ba68 100644 --- a/17 - Sort Without Articles/index-START.html +++ b/17 - Sort Without Articles/index-START.html @@ -46,7 +46,16 @@ diff --git a/18 - Adding Up Times with Reduce/index-START.html b/18 - Adding Up Times with Reduce/index-START.html index abdf4c91af..988ef65970 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..02a36a75eb 100644 --- a/19 - Webcam Fun/scripts.js +++ b/19 - Webcam Fun/scripts.js @@ -3,3 +3,97 @@ 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 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 the pixels out + let pixels = ctx.getImageData(0, 0, width, height); + //update the pixels + // pixels = redEffect(pixels); + // pixels = rgbSplit(pixels); + + pixels = greenScreen(pixels); + + ctx.globalAlpha = 0.1; + //return pixels + ctx.putImageData(pixels, 0, 0); + }, 16); +} +function takePhoto() { + //Play the sound + snap.currentTime = 0; + snap.play(); + + //Gra the data from the canvas + const data = canvas.toDataURL('img/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;// 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 + 100] = pixels.data[i + 1]; // Green + pixels.data[i - 150] = 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) { + // Add transparency to the qualifying pixels. + pixels.data[i + 3] = 0; + } + } + return pixels; +} + +getVideo(); +video.addEventListener('canplay', paintToCanvas); diff --git a/19 - Webcam Fun/style.css b/19 - Webcam Fun/style.css index 410f59d89a..6ca329cd77 100755 --- a/19 - Webcam Fun/style.css +++ b/19 - Webcam Fun/style.css @@ -2,9 +2,9 @@ html { box-sizing: border-box; } -*, *:before, *:after { +/**, *:before, *:after { box-sizing: inherit; -} +}*/ html { font-size: 10px; diff --git a/20 - Speech Detection/index-START.html b/20 - Speech Detection/index-START.html index fa472df74e..12dacf72d3 100644 --- a/20 - Speech Detection/index-START.html +++ b/20 - Speech Detection/index-START.html @@ -12,6 +12,33 @@ diff --git a/21 - Geolocation/index-START.html b/21 - Geolocation/index-START.html index f3ed587241..e4cf87de97 100644 --- a/21 - Geolocation/index-START.html +++ b/21 - Geolocation/index-START.html @@ -58,6 +58,19 @@

/*Compass: https://thenounproject.com/search/?q=compass&i=592352*/ diff --git a/22 - Follow Along Link Highlighter/index-START.html b/22 - Follow Along Link Highlighter/index-START.html index 8476112b5e..c016afaf9e 100644 --- a/22 - Follow Along Link Highlighter/index-START.html +++ b/22 - Follow Along Link Highlighter/index-START.html @@ -26,7 +26,27 @@ diff --git a/22 - Follow Along Link Highlighter/style.css b/22 - Follow Along Link Highlighter/style.css index 222e27ae68..3bd85d6f90 100644 --- a/22 - Follow Along Link Highlighter/style.css +++ b/22 - Follow Along Link Highlighter/style.css @@ -17,14 +17,16 @@ body { .wrapper { margin:0 auto; - max-width:500px; + max-width:700px; font-size: 20px; line-height: 2; position: relative; + padding: 40px; + background-color: rgba(255,255,255,.5); } a { - text-decoration: none; + text-decoration: underline; color:black; background:rgba(0,0,0,0.05); border-radius: 20px @@ -44,16 +46,19 @@ a { } .menu { - padding: 0; + padding: 20px; display: flex; list-style: none; justify-content: center; margin:100px 0; + background-color: rgba(255,255,255,.5); } .menu a { + text-decoration: none; display: inline-block; padding:5px; margin:0 20px; color:black; + font-size: 2em; } diff --git a/23 - Speech Synthesis/index-START.html b/23 - Speech Synthesis/index-START.html index e890008d36..c4053745ae 100644 --- a/23 - Speech Synthesis/index-START.html +++ b/23 - Speech Synthesis/index-START.html @@ -20,9 +20,10 @@

The Voiceinator 5000

- + + @@ -35,6 +36,43 @@

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() { + 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(false)); + + + diff --git a/23 - Speech Synthesis/style.css b/23 - Speech Synthesis/style.css index a7aaa3938b..e4e0f5f3cc 100644 --- a/23 - Speech Synthesis/style.css +++ b/23 - Speech Synthesis/style.css @@ -11,17 +11,17 @@ body { margin: 0; padding: 0; font-family: sans-serif; - background-color:#3BC1AC; + background-color:#666; display:flex; min-height: 100vh; align-items: center; background-image: - radial-gradient(circle at 100% 150%, #3BC1AC 24%, #42D2BB 25%, #42D2BB 28%, #3BC1AC 29%, #3BC1AC 36%, #42D2BB 36%, #42D2BB 40%, transparent 40%, transparent), - radial-gradient(circle at 0 150%, #3BC1AC 24%, #42D2BB 25%, #42D2BB 28%, #3BC1AC 29%, #3BC1AC 36%, #42D2BB 36%, #42D2BB 40%, transparent 40%, transparent), - radial-gradient(circle at 50% 100%, #42D2BB 10%, #3BC1AC 11%, #3BC1AC 23%, #42D2BB 24%, #42D2BB 30%, #3BC1AC 31%, #3BC1AC 43%, #42D2BB 44%, #42D2BB 50%, #3BC1AC 51%, #3BC1AC 63%, #42D2BB 64%, #42D2BB 71%, transparent 71%, transparent), - radial-gradient(circle at 100% 50%, #42D2BB 5%, #3BC1AC 6%, #3BC1AC 15%, #42D2BB 16%, #42D2BB 20%, #3BC1AC 21%, #3BC1AC 30%, #42D2BB 31%, #42D2BB 35%, #3BC1AC 36%, #3BC1AC 45%, #42D2BB 46%, #42D2BB 49%, transparent 50%, transparent), - radial-gradient(circle at 0 50%, #42D2BB 5%, #3BC1AC 6%, #3BC1AC 15%, #42D2BB 16%, #42D2BB 20%, #3BC1AC 21%, #3BC1AC 30%, #42D2BB 31%, #42D2BB 35%, #3BC1AC 36%, #3BC1AC 45%, #42D2BB 46%, #42D2BB 49%, transparent 50%, transparent); + radial-gradient(circle at 100% 150%, #666 24%, #333 25%, #333 28%, #666 29%, #666 36%, #333 36%, #333 40%, transparent 40%, transparent), + radial-gradient(circle at 0 150%, #666 24%, #333 25%, #333 28%, #666 29%, #666 36%, #333 36%, #333 40%, transparent 40%, transparent), + radial-gradient(circle at 50% 100%, #333 10%, #666 11%, #666 23%, #333 24%, #333 30%, #666 31%, #666 43%, #333 44%, #333 50%, #666 51%, #666 63%, #333 64%, #333 71%, transparent 71%, transparent), + radial-gradient(circle at 100% 50%, #333 5%, #666 6%, #666 15%, #333 16%, #333 20%, #666 21%, #666 30%, #333 31%, #333 35%, #666 36%, #666 45%, #333 46%, #333 49%, transparent 50%, transparent), + radial-gradient(circle at 0 50%, #333 5%, #666 6%, #666 15%, #333 16%, #333 20%, #666 21%, #666 30%, #333 31%, #333 35%, #666 36%, #666 45%, #333 46%, #333 49%, transparent 50%, transparent); background-size:100px 50px; } @@ -42,13 +42,13 @@ h1 { width:calc(100% + 4rem); margin: -2rem 0 2rem -2rem; padding:.5rem; - background: #ffc600; - border-bottom: 5px solid #F3C010; + background: #6666ff; + border-bottom: 5px solid #6666aa; text-align: center; font-size: 5rem; font-weight: 100; font-family: 'Pacifico', cursive; - text-shadow:3px 3px 0 #F3C010; + text-shadow:3px 3px 0 #6666aa; } @@ -75,18 +75,24 @@ input[type="select"] { } .voiceinator button { - background:#ffc600; + background:#6666ff; border:0; width: 49%; float:left; font-family: 'Pacifico', cursive; margin-bottom: 0; font-size: 2rem; - border-bottom: 5px solid #F3C010; + border-bottom: 5px solid #6666aa; cursor:pointer; position: relative; } +.voiceinator button:hover { + background: #6666aa; + color: #fff; + border-bottom-color: #111155; +} + .voiceinator button:active { top:2px; } diff --git a/24 - Sticky Nav/index-START.html b/24 - Sticky Nav/index-START.html index e7bc67e9a5..6608c5307b 100644 --- a/24 - Sticky Nav/index-START.html +++ b/24 - Sticky Nav/index-START.html @@ -54,7 +54,21 @@

A story about getting lost.

diff --git a/24 - Sticky Nav/style-START.css b/24 - Sticky Nav/style-START.css index c6d59a31b3..700674c2a3 100644 --- a/24 - Sticky Nav/style-START.css +++ b/24 - Sticky Nav/style-START.css @@ -48,6 +48,20 @@ nav { z-index: 1; } +.fixed-nav nav { + position: fixed; + box-shadow: 0 5px rgba(0,0,0,0.1); +} + +.fixed-nav li.logo { + max-width: 500px; +} + +.fixed-nav .site-wrap { + transform: scale(1); +} + + nav ul { margin: 0; padding:0; 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..060c3706ad 100644 --- a/25 - Event Capture, Propagation, Bubbling and Once/index-START.html +++ b/25 - Event Capture, Propagation, Bubbling and Once/index-START.html @@ -29,17 +29,38 @@ } .two { - background:mistyrose; + background: mistyrose; } .three { - background:coral; + background: coral; } diff --git a/26 - Stripe Follow Along Nav/index-START.html b/26 - Stripe Follow Along Nav/index-START.html index 510a0834a7..c329cd564c 100644 --- a/26 - Stripe Follow Along Nav/index-START.html +++ b/26 - Stripe Follow Along Nav/index-START.html @@ -140,8 +140,6 @@

Cool

opacity: 1; } - - .dropdownBackground { width:100px; height:100px; @@ -214,6 +212,42 @@

Cool

diff --git a/27 - Click and Drag/index-START.html b/27 - Click and Drag/index-START.html index b8609315f7..c74dcf84a7 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 8bd536b18b..96a9523bf3 100644 --- a/28 - Video Speed Controller/index-START.html +++ b/28 - Video Speed Controller/index-START.html @@ -15,6 +15,26 @@ diff --git a/29 - Countdown Timer/scripts-START.js b/29 - Countdown Timer/scripts-START.js index e69de29bb2..da32a8a334 100644 --- a/29 - Countdown Timer/scripts-START.js +++ b/29 - Countdown Timer/scripts-START.js @@ -0,0 +1,57 @@ +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) { + //Cancel out current timers + 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); + //Stop the Countdown at 0 + 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}`; + 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(); + +}); \ 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..4c35ce26f0 100644 --- a/30 - Whack A Mole/index-START.html +++ b/30 - Whack A Mole/index-START.html @@ -36,6 +36,50 @@

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; // Keep fake clicks from hapening + score++; + this.parentNode.classList.remove('up'); + scoreBoard.textContent = score; + }; + + moles.forEach(mole => mole.addEventListener('click', bonk));