From 9a4ac550de6185a5b8ead4a5acad7253d8bbcefe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Ricardo?= Date: Mon, 12 Mar 2018 16:23:49 +0000 Subject: [PATCH] Exercises done in Firefox --- .jshintrc | 3 + 01 - JavaScript Drum Kit/index-START.html | 8 +- 02 - JS and CSS Clock/index-START.html | 23 ++++ 03 - CSS Variables/index-START.html | 27 ++++- 04 - Array Cardio Day 1/index-START.html | 65 +++++++++-- 05 - Flex Panel Gallery/index-START.html | 35 +++++- 06 - Type Ahead/index-START.html | 44 ++++++++ 07 - Array Cardio Day 2/index-START.html | 41 ++++++- 08 - Fun with HTML5 Canvas/index-START.html | 52 +++++++++ 09 - Dev Tools Domination/index-START.html | 56 ++++++++-- .../index-START.html | 30 ++++++ 11 - Custom Video Player/scripts.js | 62 +++++++++++ 12 - Key Sequence Detection/index-START.html | 13 +++ 13 - Slide in on Scroll/index-START.html | 19 ++++ .../index-START.html | 62 +++++++++-- 15 - LocalStorage/index-START.html | 42 +++++++- 16 - Mouse Move Shadow/index-start.html | 25 +++++ 17 - Sort Without Articles/index-START.html | 13 +++ .../index-START.html | 20 ++++ 19 - Webcam Fun/index.html | 4 +- 19 - Webcam Fun/package.json | 2 +- 19 - Webcam Fun/scripts.js | 102 ++++++++++++++++++ 20 - Speech Detection/index-START.html | 30 +++++- 20 - Speech Detection/package.json | 2 +- 21 - Geolocation/index-START.html | 13 +++ 21 - Geolocation/package.json | 2 +- .../index-START.html | 25 ++++- 23 - Speech Synthesis/index-START.html | 50 ++++++++- 24 - Sticky Nav/index-START.html | 15 ++- 24 - Sticky Nav/style-START.css | 13 +++ .../index-START.html | 10 +- 26 - Stripe Follow Along Nav/index-START.html | 37 ++++++- 27 - Click and Drag/index-START.html | 30 ++++++ 28 - Video Speed Controller/index-START.html | 17 +++ 29 - Countdown Timer/scripts-START.js | 56 ++++++++++ 30 - Whack A Mole/index-START.html | 47 ++++++++ 36 files changed, 1048 insertions(+), 47 deletions(-) create mode 100644 .jshintrc diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000000..2b6f469f0c --- /dev/null +++ b/.jshintrc @@ -0,0 +1,3 @@ +{ + "esversion": 6 +} diff --git a/01 - JavaScript Drum Kit/index-START.html b/01 - JavaScript Drum Kit/index-START.html index 4070d32767..64d9e60d1e 100644 --- a/01 - JavaScript Drum Kit/index-START.html +++ b/01 - JavaScript Drum Kit/index-START.html @@ -57,9 +57,11 @@ - + + diff --git a/02 - JS and CSS Clock/index-START.html b/02 - JS and CSS Clock/index-START.html index ee7eaefb1f..ae8e1ea6b0 100644 --- a/02 - JS and CSS Clock/index-START.html +++ b/02 - JS and CSS Clock/index-START.html @@ -62,13 +62,36 @@ background:black; position: absolute; top:50%; + transform-origin: 100%; + transform: rotate(90deg); + transition: all 0.05s; + transition-timing-function: cubic-bezier(0.1,2.7,.58,1); } diff --git a/03 - CSS Variables/index-START.html b/03 - CSS Variables/index-START.html index 8a4f0d556e..3f3913bba2 100644 --- a/03 - CSS Variables/index-START.html +++ b/03 - CSS Variables/index-START.html @@ -21,11 +21,25 @@

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..dadc1613b2 100644 --- a/04 - Array Cardio Day 1/index-START.html +++ b/04 - Array Cardio Day 1/index-START.html @@ -31,29 +31,78 @@ // 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(function(a, b) { + // if (a.year > b.year) { + // return 1; + // } else { + // return -1; + // } + // }); + + 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 links = [...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((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..f9f7135664 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,7 +60,17 @@ margin:0; width: 100%; transition:transform 0.5s; + /* border: 1px solid red; */ + 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; @@ -67,6 +83,7 @@ } .panel.open { + flex: 5; font-size:40px; } @@ -102,7 +119,23 @@ diff --git a/06 - Type Ahead/index-START.html b/06 - Type Ahead/index-START.html index 1436886918..c7aed54991 100644 --- a/06 - Type Ahead/index-START.html +++ b/06 - Type Ahead/index-START.html @@ -17,6 +17,50 @@ diff --git a/07 - Array Cardio Day 2/index-START.html b/07 - Array Cardio Day 2/index-START.html index 969566ff78..86435ca176 100644 --- a/07 - Array Cardio Day 2/index-START.html +++ b/07 - Array Cardio Day 2/index-START.html @@ -26,16 +26,51 @@ // 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 => + ((new Date()).getFullYear() - person.year >= 19 + )); + console.log(isAdult); // Array.prototype.every() // is everyone 19 or older? - + + const allAdults = people.every(person => + ((new Date()).getFullYear() - 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); + + //comments.splice(index, 1); + + const newComments = [ + ...comments.slice(0, index), + ...comments.slice(index + 1) + ]; + console.table(comments); + console.table(newComments); diff --git a/08 - Fun with HTML5 Canvas/index-START.html b/08 - Fun with HTML5 Canvas/index-START.html index 37c148df07..4e586fdf1b 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/17 - Sort Without Articles/index-START.html b/17 - Sort Without Articles/index-START.html index 9bbd250a9b..bc9e01b7a5 100644 --- a/17 - Sort Without Articles/index-START.html +++ b/17 - Sort Without Articles/index-START.html @@ -46,7 +46,20 @@ diff --git a/18 - Adding Up Times with Reduce/index-START.html b/18 - Adding Up Times with Reduce/index-START.html index abdf4c91af..c651e4f2df 100644 --- a/18 - Adding Up Times with Reduce/index-START.html +++ b/18 - Adding Up Times with Reduce/index-START.html @@ -182,6 +182,26 @@ 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/package.json b/19 - Webcam Fun/package.json index 0c4f627d7e..32ac988fc3 100755 --- a/19 - Webcam Fun/package.json +++ b/19 - Webcam Fun/package.json @@ -9,6 +9,6 @@ "author": "", "license": "ISC", "devDependencies": { - "browser-sync": "^2.12.5" + "browser-sync": "2.23.1" } } diff --git a/19 - Webcam Fun/scripts.js b/19 - Webcam Fun/scripts.js index 00355f5a9c..4003a2bb03 100644 --- a/19 - Webcam Fun/scripts.js +++ b/19 - Webcam Fun/scripts.js @@ -1,5 +1,107 @@ +/*jshint esversion: 6 */ + const video = document.querySelector('.player'); 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.error(`OH NOOOO!`, 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); + // mess with them + //pixels = redEffect(pixels); + //pixels = rgbSplit(pixels); + //ctx.globalAlpha = 0.8; + pixels = greenScreen(pixels); + // put them back + ctx.putImageData(pixels, 0, 0); + }, 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.textContent = 'Download Image'; + 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; // r + pixels.data[i + 1] = pixels.data[i + 1] - 50;// g + pixels.data[i + 2] = pixels.data[i + 2] * 0.5;// b + } + return pixels; +} + +function rgbSplit(pixels) { + for(let i = 0; i < pixels.data.length; i+=4) { + pixels.data[i - 150] = pixels.data[i + 0]; // r + pixels.data[i + 500] = pixels.data[i + 1];// g + pixels.data[i - 550] = pixels.data[i + 2];// b + } + return pixels; +} + +function greenScreen(pixels) { + console.log('greee'); + 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', paintToCanvas); diff --git a/20 - Speech Detection/index-START.html b/20 - Speech Detection/index-START.html index fa472df74e..55623a5c5a 100644 --- a/20 - Speech Detection/index-START.html +++ b/20 - Speech Detection/index-START.html @@ -11,7 +11,35 @@ diff --git a/20 - Speech Detection/package.json b/20 - Speech Detection/package.json index ba5380f2af..f630e29cf8 100755 --- a/20 - Speech Detection/package.json +++ b/20 - Speech Detection/package.json @@ -9,6 +9,6 @@ "author": "", "license": "ISC", "devDependencies": { - "browser-sync": "^2.12.5" + "browser-sync": "^2.23.3" } } diff --git a/21 - Geolocation/index-START.html b/21 - Geolocation/index-START.html index f3ed587241..6c9f807214 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/21 - Geolocation/package.json b/21 - Geolocation/package.json index 3a6d6c7bd9..89a7afdeaa 100755 --- a/21 - Geolocation/package.json +++ b/21 - Geolocation/package.json @@ -9,6 +9,6 @@ "author": "", "license": "ISC", "devDependencies": { - "browser-sync": "^2.12.5" + "browser-sync": "2.12.5" } } diff --git a/22 - Follow Along Link Highlighter/index-START.html b/22 - Follow Along Link Highlighter/index-START.html index 8476112b5e..7a9cc4142b 100644 --- a/22 - Follow Along Link Highlighter/index-START.html +++ b/22 - Follow Along Link Highlighter/index-START.html @@ -27,7 +27,30 @@ - diff --git a/23 - Speech Synthesis/index-START.html b/23 - Speech Synthesis/index-START.html index e890008d36..edd5e3c183 100644 --- a/23 - Speech Synthesis/index-START.html +++ b/23 - Speech Synthesis/index-START.html @@ -29,12 +29,60 @@

The Voiceinator 5000

diff --git a/24 - Sticky Nav/index-START.html b/24 - Sticky Nav/index-START.html index e7bc67e9a5..ac861bfc14 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 c6d59a31b3..e7f47031f4 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; } +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..7d94e0228c 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,15 @@ diff --git a/26 - Stripe Follow Along Nav/index-START.html b/26 - Stripe Follow Along Nav/index-START.html index 510a0834a7..f458c47f48 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,41 @@

Cool

diff --git a/27 - Click and Drag/index-START.html b/27 - Click and Drag/index-START.html index b8609315f7..343be8a1e6 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..e56086d518 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..bdd5dc4266 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 timer(seconds) { + // clear any existing 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); + + // check if we should stop it! + if (secondsLeft < 0) { + clearInterval(countdown); + return; + } + // display it + 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 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; + console.log(mins); + 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..06f4392198 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 idx = Math.floor(Math.random() * holes.length); + const hole = holes[idx]; + if (hole === lastHole) { + console.log('Ah nah thats the same one'); + return randomHole(holes); + } + + lastHole = hole; + return hole; + } + + function peep() { + const time = randomTime(200, 1000); + const hole = randomHole(holes); + console.log(time, hole); + 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));