diff --git a/01 - JavaScript Drum Kit/index-START.html b/01 - JavaScript Drum Kit/index-START.html index 4070d32767..e0eabf9fdf 100644 --- a/01 - JavaScript Drum Kit/index-START.html +++ b/01 - JavaScript Drum Kit/index-START.html @@ -58,7 +58,26 @@ diff --git a/02 - JS and CSS Clock/index-START.html b/02 - JS and CSS Clock/index-START.html index 2712384201..ef983de8ca 100644 --- a/02 - JS and CSS Clock/index-START.html +++ b/02 - JS and CSS Clock/index-START.html @@ -56,6 +56,9 @@ } .hand { + transform-origin: 100%; + transform: rotate(90deg); + transition-duration(0.2s); width:50%; height:6px; background:black; @@ -66,6 +69,20 @@ diff --git a/03 - CSS Variables/index-START.html b/03 - CSS Variables/index-START.html index ca2b59d077..1781317ddb 100644 --- a/03 - CSS Variables/index-START.html +++ b/03 - CSS Variables/index-START.html @@ -22,6 +22,22 @@

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..a9acfde07c 100644 --- a/04 - Array Cardio Day 1/index-START.html +++ b/04 - Array Cardio Day 1/index-START.html @@ -31,28 +31,57 @@ // Array.prototype.filter() // 1. Filter the list of inventors for those who were born in the 1500's + let inventorsOf1500 = inventors.filter((inventor) => (inventor.year < 1600 && inventor.year >= 1500)); + console.table(inventorsOf1500); // Array.prototype.map() // 2. Give us an array of the inventors' first and last names + let names = inventors.map((inventor) => inventor.first + ' ' + inventor.last); + console.log(names); // Array.prototype.sort() // 3. Sort the inventors by birthdate, oldest to youngest + let inventorsSortByBirthday = inventors.sort((inventor1, inventor2) => inventor1.year - inventor2.year); + console.table(inventorsSortByBirthday); + // Array.prototype.reduce() // 4. How many years did all the inventors live? + let yearsOfAllInventors = inventors.reduce((i, inventor) => i + (inventor.passed - inventor.year), 0); + console.log(yearsOfAllInventors); - // 5. Sort the inventors by years lived + // 5. Sort the inventors by years lived highest at the beginning + let inventorsByYearsLived = inventors.sort((inventor1, inventor2) => (inventor2.passed - inventor2.year) - (inventor1.passed - inventor1.year)); + console.table(inventorsByYearsLived); // 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name // https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris + //let category = document.querySelector('.mw-category'); + //let links = [...category.querySelectorAll('a')].map(a => a.textContent); + //let de = links.filter(rue => rue.includes('de')); + //console.log(de); // 7. sort Exercise // Sort the people alphabetically by last name + let alphabetical = people.sort((current, next) => { + let [currentLast, currentFirst] = current.split(', '); + let [nextLast, nextFirst] = next.split(', '); + return currentLast < nextLast ? -1 : 1; + }); + console.log(alphabetical); // 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' ]; + let numberOfAppearance = data.reduce((appearance, item) => { + if(!appearance[item]) { + appearance[item] = 0; + } + appearance[item]++; + return appearance; + }, {}); + console.log(numberOfAppearance); diff --git a/05 - Flex Panel Gallery/index-START.html b/05 - Flex Panel Gallery/index-START.html index e1d643ad5c..996e30ef51 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; + justify-content: center; + align-items: center; + display: flex; + flex: 1; + flex-direction: column; } @@ -54,6 +60,24 @@ 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 { @@ -68,6 +92,7 @@ .panel.open { font-size:40px; + flex: 5; } .cta { @@ -108,6 +133,20 @@ diff --git a/06 - Type Ahead/index-START.html b/06 - Type Ahead/index-START.html index 1436886918..821d4706d0 100644 --- a/06 - Type Ahead/index-START.html +++ b/06 - Type Ahead/index-START.html @@ -15,7 +15,41 @@ diff --git a/07 - Array Cardio Day 2/index-START.html b/07 - Array Cardio Day 2/index-START.html index 969566ff78..fa94a91ac9 100644 --- a/07 - Array Cardio Day 2/index-START.html +++ b/07 - Array Cardio Day 2/index-START.html @@ -25,16 +25,24 @@ ]; // Some and Every Checks - // Array.prototype.some() // is at least one person 19 or older? - // Array.prototype.every() // is everyone 19 or older? + // Array.prototype.some() // is at least one person 19? + // Array.prototype.every() // is everyone 19? + let one19 = people.some((person) => (new Date().getFullYear() - person.year) === 19); + let every = people.every(person => (new Date().getFullYear() - person.year) === 19); + console.log(one19); + console.log(every); // 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 + let comment = comments.find((comm) => comm.id === 823423); + console.log(comment); // Array.prototype.findIndex() // Find the comment with this ID // delete the comment with the ID of 823423 + let index = comments.findIndex(comm => comm.id === 823423); + console.log(index); diff --git a/08 - Fun with HTML5 Canvas/index-START.html b/08 - Fun with HTML5 Canvas/index-START.html index 37c148df07..9ec6c132ac 100644 --- a/08 - Fun with HTML5 Canvas/index-START.html +++ b/08 - Fun with HTML5 Canvas/index-START.html @@ -7,8 +7,52 @@ + const canvas = document.querySelector('#draw'); + const context = canvas.getContext('2d'); + canvas.height = window.innerHeight; + canvas.width = window.innerWidth; + context.strokeStyle = 'BADA55'; + context.lineJoin = 'round'; + context.lineCap = 'round'; + + let lastX = 0; + let lastY = 0; + let isDrawing = false; + let hue = 0; + let direction = true; + + function draw(e) { + if (!isDrawing) return; + console.log(e); + context.strokeStyle = `hsl(${hue}, 100%, 50%)`; + context.beginPath(); + context.moveTo(lastX, lastY); + context.lineTo(e.offsetX, e.offsetY); + context.stroke(); + lastX = e.offsetX; + lastY = e.offsetY; + hue++; + if (context.lineWidth >= 100 || context.lineWidth < 0) { + direction = !direction; + } + if (direction) { + context.lineWidth++; + } else { + context.lineWidth--; + } + } + + window.addEventListener('mousemove', draw); + window.addEventListener('mousedown', (e) => { + isDrawing = true; + lastX = e.offsetX; + lastY = e.offsetY; + }); + window.addEventListener('mouseup', () => isDrawing = false); + window.addEventListener('mouseleave', () => isDrawing = false); + + diff --git a/17 - Sort Without Articles/index-START.html b/17 - Sort Without Articles/index-START.html index cfaf3e0440..0d0e29dde0 100644 --- a/17 - Sort Without Articles/index-START.html +++ b/17 - Sort Without Articles/index-START.html @@ -44,8 +44,17 @@ diff --git a/18 - Adding Up Times with Reduce/index-START.html b/18 - Adding Up Times with Reduce/index-START.html index abdf4c91af..857ffc71b7 100644 --- a/18 - Adding Up Times with Reduce/index-START.html +++ b/18 - Adding Up Times with Reduce/index-START.html @@ -182,6 +182,21 @@ diff --git a/19 - Webcam Fun/index.html b/19 - Webcam Fun/index.html index d4ffc4dc2a..00e331f632 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..0d28351d75 100644 --- a/19 - Webcam Fun/scripts.js +++ b/19 - Webcam Fun/scripts.js @@ -3,3 +3,98 @@ const canvas = document.querySelector('.photo'); const ctx = canvas.getContext('2d'); const strip = document.querySelector('.strip'); const snap = document.querySelector('.snap'); +const filter = {}; +document.querySelectorAll('.filterSelector input').forEach(input => { + filter[input.id] = input.checked; + input.addEventListener('change', (e) => filter[e.target.id] = e.target.checked); +}); + +function getVideo() { + navigator.mediaDevices.getUserMedia({audio: false, video: true}) + .then(videoStream => { + console.log(videoStream); + video.src = window.URL.createObjectURL(videoStream); + video.play(); + }) + .catch(error => console.log(error)); +} + +function paintPhoto() { + const height = video.videoHeight; + const width = video.videoWidth; + + canvas.height = height; + canvas.width = width; + + return setInterval(() => { + ctx.drawImage(video, 0, 0, width, height); + let pixels = ctx.getImageData(0, 0, width, height); + if (filter.redFilter) { + pixels = redEffect(pixels); + } + if (filter.slowFilter) { + ctx.globalAlpha = 0.1; + } else { + ctx.globalAlpha = 1; + } + if (filter.rgbFilter) { + pixels = rgbSplit(pixels); + } + if (filter.colorFilter) { + pixels = removeColor(pixels); + } + ctx.putImageData(pixels, 0, 0); + }, 16); +} + +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] - 100; + pixels.data[i+2] = pixels.data[i+2] - 100; + } + return pixels; +} + +function rgbSplit(pixels) { + for(let i = 0; i < pixels.data.length; i += 4) { + pixels.data[i+300] = pixels.data[i+0]; + pixels.data[i-150] = pixels.data[i+1]; + pixels.data[i+180] = pixels.data[i+2]; + } + return pixels; +} + +function removeColor(pixels) { + const levels = {}; + document.querySelectorAll('.rgb input').forEach(input => levels[input.name] = input.value); + + for (let i = 0; i < pixels.data.length; i += 4) { + let red = pixels.data[i]; + let green = pixels.data[i+1]; + let blue = pixels.data[i+2]; + + if (red >= levels.rmin && red <= levels.rmax + && green >= levels.gmin && green <= levels.gmax + && blue >= levels.bmin && blue <= levels.bmax) { + pixels.data[i+3] = 0; + } + } + return pixels; +} + +function takePhoto() { + snap.currentTime = 0; + snap.play(); + + const data = canvas.toDataURL('image/jpeg'); + + const link = document.createElement('a'); + link.href = data; + link.innerHTML = `screenshot`; + link.setAttribute('downloda', 'webcam_picture'); + strip.insertBefore(link, strip.firstChild); +} +getVideo(); + +video.addEventListener('canplay', paintPhoto); diff --git a/20 - Speech Detection/index-START.html b/20 - Speech Detection/index-START.html index d3395cca35..dab4e9c46f 100644 --- a/20 - Speech Detection/index-START.html +++ b/20 - Speech Detection/index-START.html @@ -12,6 +12,26 @@ diff --git a/21 - Geolocation/index-START.html b/21 - Geolocation/index-START.html index a1b981b1cd..7b22c2169a 100644 --- a/21 - Geolocation/index-START.html +++ b/21 - Geolocation/index-START.html @@ -57,6 +57,12 @@

/*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..59812118bc 100644 --- a/22 - Follow Along Link Highlighter/index-START.html +++ b/22 - Follow Along Link Highlighter/index-START.html @@ -27,6 +27,27 @@ diff --git a/23 - Speech Synthesis/index-START.html b/23 - Speech Synthesis/index-START.html index e890008d36..9e1f004fc3 100644 --- a/23 - Speech Synthesis/index-START.html +++ b/23 - Speech Synthesis/index-START.html @@ -29,12 +29,46 @@

The Voiceinator 5000

diff --git a/24 - Sticky Nav/index-START.html b/24 - Sticky Nav/index-START.html index e7bc67e9a5..61900fa7ad 100644 --- a/24 - Sticky Nav/index-START.html +++ b/24 - Sticky Nav/index-START.html @@ -55,6 +55,21 @@

A story about getting lost.

diff --git a/24 - Sticky Nav/style-START.css b/24 - Sticky Nav/style-START.css index c6d59a31b3..71d8e8b53a 100644 --- a/24 - Sticky Nav/style-START.css +++ b/24 - Sticky Nav/style-START.css @@ -46,6 +46,10 @@ nav { transition:all 0.5s; position: relative; z-index: 1; + +} +.fixed nav { + position: fixed; } nav ul { @@ -72,6 +76,10 @@ li.logo { font-size: 30px; } +.fixed .logo { + max-width: 500px; +} + li.logo a { color:black; } 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..69840f7c96 100644 --- a/25 - Event Capture, Propagation, Bubbling and Once/index-START.html +++ b/25 - Event Capture, Propagation, Bubbling and Once/index-START.html @@ -39,6 +39,18 @@ diff --git a/26 - Stripe Follow Along Nav/index-START.html b/26 - Stripe Follow Along Nav/index-START.html index 9780d0d1ac..0c870eee08 100644 --- a/26 - Stripe Follow Along Nav/index-START.html +++ b/26 - Stripe Follow Along Nav/index-START.html @@ -208,6 +208,44 @@

Cool

diff --git a/27 - Click and Drag/index-START.html b/27 - Click and Drag/index-START.html index b8609315f7..430d89f6d8 100644 --- a/27 - Click and Drag/index-START.html +++ b/27 - Click and Drag/index-START.html @@ -35,6 +35,34 @@ diff --git a/28 - Video Speed Controller/index-START.html b/28 - Video Speed Controller/index-START.html index c4cbd4259a..908576fa9c 100644 --- a/28 - Video Speed Controller/index-START.html +++ b/28 - Video Speed Controller/index-START.html @@ -15,6 +15,21 @@ diff --git a/29 - Countdown Timer/scripts-START.js b/29 - Countdown Timer/scripts-START.js index e69de29bb2..a859c5b4e1 100644 --- a/29 - Countdown Timer/scripts-START.js +++ b/29 - Countdown Timer/scripts-START.js @@ -0,0 +1,49 @@ +let countdown; +const displayTime = document.querySelector('.display__time-left'); +const endTimeDisplay = document.querySelector('.display__end-time'); +const buttons = document.querySelectorAll('.timer__button'); +const form = document.querySelector('#custom'); +const minutesInput = form.querySelector('input'); + +function startCoundDown(seconds) { + clearInterval(countdown); + const start = Date.now(); + const end = start + (seconds * 1000); + displayEndTime(end); + + displayRemainingTime(Math.round(end - start)/1000); + countdown = setInterval(() => { + const now = Date.now(); + const timeRemaining = Math.round((end - now) / 1000); + if (timeRemaining < 0) { + clearInterval(countdown); + return; + } + displayRemainingTime(timeRemaining); + }, 1000); +} + +function displayRemainingTime(seconds) { + const remainingMinutes = Math.floor(seconds / 60); + const remainingSeconds = seconds % 60; + const text = `${remainingMinutes}:${remainingSeconds < 10 ? '0' : ''}${remainingSeconds}`; + displayTime.textContent = text; + document.title = text; +} + +function displayEndTime(end) { + end = new Date(end); + const hours = end.getHours(); + const minutes = end.getMinutes(); + endTimeDisplay.textContent = `Be back at ${hours}:${minutes > 9 ? '' : '0'}${minutes}`; +} + +buttons.forEach(button => button.addEventListener('click', function() { + startCoundDown(this.dataset['time']); +})); + +form.addEventListener('submit', (e) => { + e.preventDefault(); + startCoundDown(minutesInput.value * 60); + minutesInput.reset(); +}); diff --git a/30 - Whack A Mole/index-START.html b/30 - Whack A Mole/index-START.html index 2014ff458c..801552ab92 100644 --- a/30 - Whack A Mole/index-START.html +++ b/30 - Whack A Mole/index-START.html @@ -36,7 +36,44 @@

Whack-a-mole! 0

const holes = document.querySelectorAll('.hole'); const scoreBoard = document.querySelector('.score'); const moles = document.querySelectorAll('.mole'); + let lastIndex; + let timeUp = true; + + function randomTime(min, max) { + return Math.round(Math.random() * (max - min) + min); + } + function randomHole(holes) { + const index = Math.floor(Math.random() * holes.length); + if (index === lastIndex) { + return randomHole(holes); + } + lastIndex = index; + return holes[index]; + } + + function showMole() { + const hole = randomHole(holes); + hole.classList.add('up'); + setTimeout(() => { + hole.classList.remove('up'); + if (!timeUp) showMole(); + }, randomTime(200, 1000)); + } + + function startGame() { + timeUp = false; + scoreBoard.textContent = 0; + showMole(); + setTimeout(() => timeUp = true); + } + + function cachedMole() { + scoreBoard.textContent = parseInt(scoreBoard.textContent) + 1; + this.parentElement.classList.remove('up'); + } + + moles.forEach(mole => mole.addEventListener('click', cachedMole));