From d8d5714adbe6cc38770a44babaf52f504d2d713f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81nderson=20M=C3=A9ndez=20Abello?= <Ánderson Méndez Abello> Date: Tue, 27 Dec 2016 19:09:16 +0100 Subject: [PATCH 1/4] 15 challenges of javascript30 --- 01 - JavaScript Drum Kit/index-START.html | 29 +++++++ 01 - JavaScript Drum Kit/style.css | 2 +- 02 - JS + CSS Clock/index-START.html | 30 +++++++ 03 - CSS Variables/index-START.html | 32 ++++++- 04 - Array Cardio Day 1/index-START.html | 72 ++++++++++++++++ 05 - Flex Panel Gallery/index-FINISHED.html | 1 - 05 - Flex Panel Gallery/index-START.html | 31 +++++++ 06 - Type Ahead/index-START.html | 47 ++++++++++ 06 - Type Ahead/style.css | 1 - 07 - Array Cardio Day 2/index-FINISHED.html | 5 +- 07 - Array Cardio Day 2/index-START.html | 38 ++++----- 08 - Fun with HTML5 Canvas/index-START.html | 56 ++++++++++++ 09 - Dev Tools Domination/index-START.html | 44 ++++++++++ .../index-START.html | 30 +++++++ 11 - Custom Video Player/scripts.js | 69 +++++++++++++++ 12 - Key Sequence Detection/index-START.html | 21 +++++ 13 - Slide in on Scroll/index-START.html | 23 +++-- .../index-START.html | 53 +++++++++++- 15 - LocalStorage/index-START.html | 85 ++++++++++++++++++- 19 files changed, 629 insertions(+), 40 deletions(-) diff --git a/01 - JavaScript Drum Kit/index-START.html b/01 - JavaScript Drum Kit/index-START.html index 4070d32767..82a36c88b4 100644 --- a/01 - JavaScript Drum Kit/index-START.html +++ b/01 - JavaScript Drum Kit/index-START.html @@ -59,6 +59,35 @@ diff --git a/01 - JavaScript Drum Kit/style.css b/01 - JavaScript Drum Kit/style.css index 3e0a320b37..e0bc4aeb11 100644 --- a/01 - JavaScript Drum Kit/style.css +++ b/01 - JavaScript Drum Kit/style.css @@ -23,7 +23,7 @@ body,html { margin:1rem; font-size: 1.5rem; padding:1rem .5rem; - transition:all .07s; + transition:all 1.07s; width:100px; text-align: center; color:white; diff --git a/02 - JS + CSS Clock/index-START.html b/02 - JS + CSS Clock/index-START.html index 259280d228..76ae69f79a 100644 --- a/02 - JS + CSS Clock/index-START.html +++ b/02 - JS + CSS Clock/index-START.html @@ -61,12 +61,42 @@ background:black; position: absolute; top:50%; + transform-origin: 100%; + transform: rotate(90deg); + transition: all .5s; + transition-timing-function: cubic-bezier(0.1, 2.7, 0.58, 1); } diff --git a/03 - CSS Variables/index-START.html b/03 - CSS Variables/index-START.html index bf0f33e3ba..ebdd81923e 100644 --- a/03 - CSS Variables/index-START.html +++ b/03 - CSS Variables/index-START.html @@ -9,7 +9,7 @@

Update CSS Variables with JS

- + @@ -21,6 +21,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 089352c8a6..4345d23f2a 100644 --- a/04 - Array Cardio Day 1/index-START.html +++ b/04 - Array Cardio Day 1/index-START.html @@ -28,28 +28,100 @@ // Array.prototype.filter() // 1. Filter the list of inventors for those who were born in the 1500's + console.log('>> 1'); + const fifteen = inventors.filter(e => (e.year >= 1499 && e.year <= 1599)); + console.table(fifteen); + // Array.prototype.map() // 2. Give us an array of the inventory first and last names + console.log('>> 2'); + const nameFirsts = inventors.map(e => `${e.first} ${e.last}`); + + console.log(nameFirsts); + // Array.prototype.sort() // 3. Sort the inventors by birthdate, oldest to youngest + + console.log('>> 3'); + const sortBirthdate = inventors.sort((a, b) => a.year - b.year); + + console.table(sortBirthdate); + // Array.prototype.reduce() // 4. How many years did all the inventors live? + console.log('>> 4'); + const yearsAllInventors = inventors.reduce(function(a, b){ + + const Byears = b.passed - b.year; + return a+Byears; + + }, 0); + console.log(yearsAllInventors); + // 5. Sort the inventors by years lived + console.log('>> 5'); + const oldestToYoungest = inventors.sort(function (a, b){ + + const Ayears = a.passed - a.year; + const Byears = b.passed - b.year; + + return Byears > Ayears ? 1 : -1; + + }); + + console.table(oldestToYoungest); + // 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 + console.log('>> 6'); + const alphabeticallySort = people.sort((a, b) => { + const [aLast, aFirst] = a.split(', '); + const [bLast, bFirst] = b.split(', '); + + if(bLast < aLast){ + return 1; + } + + return -1; + }); + + console.log(alphabeticallySort); // 8. Reduce Exercise // Sum up the instances of each of these + + console.log('>> 8'); 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-FINISHED.html b/05 - Flex Panel Gallery/index-FINISHED.html index adb9060f5f..243f8a221d 100644 --- a/05 - Flex Panel Gallery/index-FINISHED.html +++ b/05 - Flex Panel Gallery/index-FINISHED.html @@ -44,7 +44,6 @@ background-position:center; flex: 1; justify-content: center; - align-items: center; display: flex; flex-direction: column; } diff --git a/05 - Flex Panel Gallery/index-START.html b/05 - Flex Panel Gallery/index-START.html index e1d643ad5c..9d112440ef 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; + align-items: center; + justify-content: center; + display: flex; + flex-direction: column; } @@ -54,8 +60,17 @@ margin:0; width: 100%; transition:transform 0.5s; + flex: 1 0 auto; + display: flex; + align-items: 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 { text-transform: uppercase; font-family: 'Amatic SC', cursive; @@ -67,6 +82,7 @@ } .panel.open { + flex: 5; font-size:40px; } @@ -108,6 +124,21 @@ diff --git a/06 - Type Ahead/index-START.html b/06 - Type Ahead/index-START.html index 1436886918..ec43417c57 100644 --- a/06 - Type Ahead/index-START.html +++ b/06 - Type Ahead/index-START.html @@ -17,6 +17,53 @@ diff --git a/06 - Type Ahead/style.css b/06 - Type Ahead/style.css index 155164bae9..36dc55f30e 100644 --- a/06 - Type Ahead/style.css +++ b/06 - Type Ahead/style.css @@ -22,7 +22,6 @@ margin: 0; text-align: center; outline:0; - border:0; border: 10px solid #F7F7F7; width: 120%; left: -10%; diff --git a/07 - Array Cardio Day 2/index-FINISHED.html b/07 - Array Cardio Day 2/index-FINISHED.html index e39d35f79a..c8e5b25d3b 100644 --- a/07 - Array Cardio Day 2/index-FINISHED.html +++ b/07 - Array Cardio Day 2/index-FINISHED.html @@ -2,9 +2,10 @@ - Document + Array Cardio 💪💪 +

Psst: have a look at the JavaScript Console 💁

diff --git a/08 - Fun with HTML5 Canvas/index-START.html b/08 - Fun with HTML5 Canvas/index-START.html index 37c148df07..e1454e8459 100644 --- a/08 - Fun with HTML5 Canvas/index-START.html +++ b/08 - Fun with HTML5 Canvas/index-START.html @@ -7,6 +7,62 @@ + + + + diff --git a/16 - Mouse Move Shadow/index-start.html b/16 - Mouse Move Shadow/index-start.html index 4328eaf6ab..d4bca97043 100644 --- a/16 - Mouse Move Shadow/index-start.html +++ b/16 - Mouse Move Shadow/index-start.html @@ -1,13 +1,15 @@ + Mouse Shadow +
-

🔥WOAH!

+

🤗 WOAH!

- - + + \ No newline at end of file diff --git a/17 - Sort Without Articles/index-START.html b/17 - Sort Without Articles/index-START.html index cfaf3e0440..7d8fd78a77 100644 --- a/17 - Sort Without Articles/index-START.html +++ b/17 - Sort Without Articles/index-START.html @@ -1,9 +1,11 @@ + Sort Without Articles + - + - + + \ No newline at end of file diff --git a/18 - Adding Up Times with Reduce/index-START.html b/18 - Adding Up Times with Reduce/index-START.html index 3eaee0f3ef..61a8305e38 100644 --- a/18 - Adding Up Times with Reduce/index-START.html +++ b/18 - Adding Up Times with Reduce/index-START.html @@ -182,6 +182,27 @@ diff --git a/19 - Webcam Fun/index.html b/19 - Webcam Fun/index.html index d4ffc4dc2a..b4b47a16da 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..5ad7ed990d 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'); + + + +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(`Errorrrrr`, 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); + let pixels = ctx.getImageData(0,0,width, height); + //pixels = rgbSplit(pixels); + pixels = greenScreen(pixels); + //ctx.globalAlpha = 0.1; + 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.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 - 650] = 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 += 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) { + pixels.data[i + 3] = 0; + } + } + + return pixels; +} + + +getVideo(); + +video.addEventListener('canplay', paintToCanvas); \ No newline at end of file diff --git a/20 - Speech Detection/index-START.html b/20 - Speech Detection/index-START.html index d3395cca35..a2a427011a 100644 --- a/20 - Speech Detection/index-START.html +++ b/20 - Speech Detection/index-START.html @@ -12,6 +12,40 @@ From 78d22711e9dba992cea4c7e63d8bfcf6a2d00491 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81nderson=20M=C3=A9ndez=20Abello?= <Ánderson Méndez Abello> Date: Mon, 23 Jan 2017 13:33:56 +0100 Subject: [PATCH 3/4] 22, 23, 24 challenges --- .../index-START.html | 22 +++++++++- 23 - Speech Synthesis/index-START.html | 41 +++++++++++++++++++ 24 - Sticky Nav/index-START.html | 2 +- 3 files changed, 63 insertions(+), 2 deletions(-) diff --git a/22 - Follow Along Link Highlighter/index-START.html b/22 - Follow Along Link Highlighter/index-START.html index 8476112b5e..cce3f5452b 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/23 - Speech Synthesis/index-START.html b/23 - Speech Synthesis/index-START.html index e890008d36..b0b48e6365 100644 --- a/23 - Speech Synthesis/index-START.html +++ b/23 - Speech Synthesis/index-START.html @@ -35,6 +35,47 @@

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('textarea').textContent; + + function populateVoices() { + voices = this.getVoices(); + voicesDropdown.innerHTML = voices + .map(voice => ``).join(''); + } + + function changeVoice(event) { + console.log(voices); + msg.voice = voices.find(voice => voice.name === this.value); + console.log(msg.voice); + toogle(); + } + + function toogle(startOver = true) { + + speechSynthesis.cancel(); + + if (startOver) { + speechSynthesis.speak(msg); + } + + } + + function setOption(){ + + console.log(this.name, this.value); + msg[this.name] = this.value; + toogle(); + + } + + + speechSynthesis.addEventListener('voiceschanged', populateVoices); + voicesDropdown.addEventListener('change', changeVoice); + options.forEach(option => option.addEventListener('change', setOption)); + speakButton.addEventListener('click', toogle); + stopButton.addEventListener('click', () => toogle(false)); + diff --git a/24 - Sticky Nav/index-START.html b/24 - Sticky Nav/index-START.html index 4982537eea..90f69ebb72 100644 --- a/24 - Sticky Nav/index-START.html +++ b/24 - Sticky Nav/index-START.html @@ -65,7 +65,7 @@

A story about getting lost.

document.body.style.paddingTop = 0; document.body.classList.remove('fixed-nav'); } - } + } window.addEventListener('scroll', fixNav); From f3930d28932fb111dd392c44ec147806b3952ad4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81nderson=20M=C3=A9ndez=20Abello?= <Ánderson Méndez Abello> Date: Thu, 2 Mar 2017 21:14:55 +0100 Subject: [PATCH 4/4] last 5 challenges of javascript30 --- .../index-START.html | 16 +++++- 26 - Stripe Follow Along Nav/index-START.html | 38 +++++++++++++ 27 - Click and Drag/index-START.html | 30 +++++++++++ 28 - Video Speed Controller/index-START.html | 24 ++++++++- 29 - Countown Timer/scripts-START.js | 53 +++++++++++++++++++ 30 - Whack A Mole/index-START.html | 47 ++++++++++++++++ 6 files changed, 206 insertions(+), 2 deletions(-) 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..6913985885 100644 --- a/25 - Event Capture, Propagation, Bubbling and Once/index-START.html +++ b/25 - Event Capture, Propagation, Bubbling and Once/index-START.html @@ -9,6 +9,7 @@
+
@@ -37,8 +38,21 @@ } - diff --git a/26 - Stripe Follow Along Nav/index-START.html b/26 - Stripe Follow Along Nav/index-START.html index 9780d0d1ac..ee23e5f486 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..5b6e1ef4ab 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 c4cbd4259a..8487d38536 100644 --- a/28 - Video Speed Controller/index-START.html +++ b/28 - Video Speed Controller/index-START.html @@ -8,13 +8,35 @@
- +
diff --git a/29 - Countown Timer/scripts-START.js b/29 - Countown Timer/scripts-START.js index e69de29bb2..1efdc0dd7a 100644 --- a/29 - Countown Timer/scripts-START.js +++ b/29 - Countown Timer/scripts-START.js @@ -0,0 +1,53 @@ +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; + displayTimer(seconds); + displayEndTime(then); + + countdown = setInterval(()=> { + const secondsLeft = Math.round((then - Date.now()) / 1000); + if(secondsLeft < 0) { + clearInterval(countdown); + return; + } + + displayTimer(secondsLeft); + }, 1000); + +} + +function displayTimer(secondsLeft){ + const seconds = secondsLeft % 60; + const minutes = Math.floor(secondsLeft / 60); + const hour = Math.round(minutes / 60); + display = `${hour}:${minutes<10 ? '0' + minutes:minutes}:${seconds<10?'0' + seconds:seconds}`; + 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}:${minutes<10?'0'+minutes: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..0394de84c7 100644 --- a/30 - Whack A Mole/index-START.html +++ b/30 - Whack A Mole/index-START.html @@ -36,6 +36,53 @@

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('repe'); + 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 blonk(e) { + if(!e.isTrusted) return; + score++; + scoreBoard.textContent = score; + this.classList.remove('up'); + } + + moles.forEach(mole => mole.addEventListener('click', blonk));