From e91bd8c12556d1b9339986096cc7a16667d84747 Mon Sep 17 00:00:00 2001 From: Steven Scaffidi Date: Wed, 11 Jan 2017 13:19:30 -0800 Subject: [PATCH 1/3] fun with vanilla js --- 01 - JavaScript Drum Kit/index-START.html | 19 ++++++++++ 02 - JS + CSS Clock/index-START.html | 22 +++++++++++- 03 - CSS Variables/index-START.html | 23 ++++++++++++ 04 - Array Cardio Day 1/index-START.html | 30 +++++++++++++++- 05 - Flex Panel Gallery/index-START.html | 28 +++++++++++++++ 06 - Type Ahead/index-START.html | 37 ++++++++++++++++++- 07 - Array Cardio Day 2/index-START.html | 21 +++++++++-- 08 - Fun with HTML5 Canvas/index-START.html | 40 +++++++++++++++++++++ 8 files changed, 215 insertions(+), 5 deletions(-) diff --git a/01 - JavaScript Drum Kit/index-START.html b/01 - JavaScript Drum Kit/index-START.html index 4070d32767..d29f84319f 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 + CSS Clock/index-START.html b/02 - JS + CSS Clock/index-START.html index 2712384201..e63904092a 100644 --- a/02 - JS + CSS Clock/index-START.html +++ b/02 - JS + CSS Clock/index-START.html @@ -53,6 +53,7 @@ width: 100%; height: 100%; transform: translateY(-3px); /* account for the height of the clock hands */ + transition: all 0.05s; } .hand { @@ -61,13 +62,32 @@ background:black; position: absolute; top:50%; + transform-origin: 100%; } diff --git a/03 - CSS Variables/index-START.html b/03 - CSS Variables/index-START.html index ca2b59d077..b284c3f632 100644 --- a/03 - CSS Variables/index-START.html +++ b/03 - CSS Variables/index-START.html @@ -21,6 +21,21 @@

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..e33bf3b698 100644 --- a/04 - Array Cardio Day 1/index-START.html +++ b/04 - Array Cardio Day 1/index-START.html @@ -31,28 +31,56 @@ // Array.prototype.filter() // 1. Filter the list of inventors for those who were born in the 1500's + const fifInventors = inventors.filter(inv => (inv.year >= 1500 && inv.year < 1600)); + console.log(fifInventors); // Array.prototype.map() // 2. Give us an array of the inventors' first and last names + const nameArray = inventors.map(inv => (`${inv.first} ${inv.last}`)); + console.log(nameArray); // Array.prototype.sort() // 3. Sort the inventors by birthdate, oldest to youngest + const oldestToYoungest = inventors.sort((a, b) => (a.year < b.year ? -1 : 1)); + console.log(oldestToYoungest); // Array.prototype.reduce() // 4. How many years did all the inventors live? + const cumulativeLived = inventors.reduce((total, i) => (total + (i.passed - i.year)), 0); + console.log(cumulativeLived); // 5. Sort the inventors by years lived + const yearsLivedUtil = (born, died) => (died - born); + const yearsLived = inventors.sort((a, b) => (yearsLivedUtil(a.year, a.passed) < yearsLivedUtil(b.year, b.passed) ? -1 : 1)); + console.log(yearsLived); // 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 streets = document.querySelector('.mw-category'); + const links = Array.from(streets.querySelectorAll('a')); + const containsDe = links.map(link => link.textContent).filter(text => text.includes('de')); + console.log(containsDe); // 7. sort Exercise // Sort the people alphabetically by last name + const byLastName = people.sort((last, current) => { + const [lastName] = last.split(','); + const [currentName] = current.split(','); + return lastName < currentName ? -1 : 1; + }); + console.log(byLastName); // 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 tally = data.reduce((obj, current) => { + if (!obj[current]) { + obj[current] = 0; + } + obj[current] += 1; + return obj; + }, {}); + console.log(tally); diff --git a/05 - Flex Panel Gallery/index-START.html b/05 - Flex Panel Gallery/index-START.html index e1d643ad5c..e5852adb26 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; + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; } @@ -54,8 +60,16 @@ margin:0; width: 100%; transition:transform 0.5s; + display: flex; + align-items: center; + justify-content: center; + flex: 1 0 auto; } + .panel > *:first-child { transform: translateY(-100%); } + .panel > *:last-child { transform: translateY(100%);} + .panel.open-active > *:first-child, .panel.open-active > *:last-child { transform: translateY(0); } + .panel p { text-transform: uppercase; font-family: 'Amatic SC', cursive; @@ -67,6 +81,7 @@ } .panel.open { + flex: 5; font-size:40px; } @@ -107,7 +122,20 @@ diff --git a/06 - Type Ahead/index-START.html b/06 - Type Ahead/index-START.html index 1436886918..64da86471e 100644 --- a/06 - Type Ahead/index-START.html +++ b/06 - Type Ahead/index-START.html @@ -15,7 +15,42 @@ diff --git a/07 - Array Cardio Day 2/index-START.html b/07 - Array Cardio Day 2/index-START.html index 969566ff78..d564f76c92 100644 --- a/07 - Array Cardio Day 2/index-START.html +++ b/07 - Array Cardio Day 2/index-START.html @@ -21,21 +21,38 @@ { text: 'Super good', id: 823423 }, { text: 'You are the best', id: 2039842 }, { text: 'Ramen is my fav food ever', id: 123523 }, - { text: 'Nice Nice Nice!', id: 542328 } + { text: 'Nice Nice Nice!', id: 542328 }, ]; // Some and Every Checks // Array.prototype.some() // is at least one person 19 or older? + const todayYear = (new Date()).getFullYear(); + const nineteen = people.some(person => (todayYear - person.year >= 19)); + console.log(nineteen); + // Array.prototype.every() // is everyone 19 or older? + const nineteenEvery = people.every(person => (todayYear - person.year >= 19)); + console.log(nineteenEvery); // 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 + function commentWithId (commentId, id = 823423) { + return commentId === id; + } + const commentOne = comments.find(({ id }) => commentWithId(id)); + console.log(commentOne); // Array.prototype.findIndex() // Find the comment with this ID + const commentOneIndex = comments.findIndex(({ id }) => commentWithId(id)); + console.log(commentOneIndex); // delete the comment with the ID of 823423 - + const newComments = [ + ...comments.slice(0, commentOneIndex), + ...comments.slice(commentOneIndex + 1), + ]; + 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..2215775cb1 100644 --- a/08 - Fun with HTML5 Canvas/index-START.html +++ b/08 - Fun with HTML5 Canvas/index-START.html @@ -7,6 +7,46 @@ diff --git a/17 - Sort Without Articles/index-START.html b/17 - Sort Without Articles/index-START.html index cfaf3e0440..2697977332 100644 --- a/17 - Sort Without Articles/index-START.html +++ b/17 - Sort Without Articles/index-START.html @@ -43,8 +43,31 @@ diff --git a/18 - Adding Up Times with Reduce/index-START.html b/18 - Adding Up Times with Reduce/index-START.html index 3eaee0f3ef..4aba495d54 100644 --- a/18 - Adding Up Times with Reduce/index-START.html +++ b/18 - Adding Up Times with Reduce/index-START.html @@ -182,6 +182,22 @@ diff --git a/21 - Geolocation/index-START.html b/21 - Geolocation/index-START.html index a1b981b1cd..e484e60c25 100644 --- a/21 - Geolocation/index-START.html +++ b/21 - Geolocation/index-START.html @@ -57,6 +57,13 @@

/*Compass: https://thenounproject.com/search/?q=compass&i=592352*/ From be18a47c6561d6be2befa42c407acb31759889f8 Mon Sep 17 00:00:00 2001 From: Steven Scaffidi Date: Tue, 24 Jan 2017 15:34:55 -0800 Subject: [PATCH 3/3] need to solve the rest at home --- .tern-project | 8 +++ .../index-START.html | 19 ++++++- 23 - Speech Synthesis/index-START.html | 41 +++++++++++++--- 24 - Sticky Nav/index-START.html | 16 +++++- 24 - Sticky Nav/style-START.css | 13 +++++ .../index-START.html | 13 ++++- 26 - Stripe Follow Along Nav/index-START.html | 32 ++++++++++++ 27 - Click and Drag/index-START.html | 31 ++++++++++++ 28 - Video Speed Controller/index-START.html | 17 +++++++ 29 - Countdown Timer/scripts-START.js | 49 +++++++++++++++++++ 30 - Whack A Mole/index-START.html | 48 ++++++++++++++++++ 11 files changed, 277 insertions(+), 10 deletions(-) create mode 100644 .tern-project diff --git a/.tern-project b/.tern-project new file mode 100644 index 0000000000..d6340ba088 --- /dev/null +++ b/.tern-project @@ -0,0 +1,8 @@ +{ + "ecmaVersion": 6, + "libs": [ + "browser", + "jquery" + ], + "plugins": {} +} \ No newline at end of file diff --git a/22 - Follow Along Link Highlighter/index-START.html b/22 - Follow Along Link Highlighter/index-START.html index 8476112b5e..40115d233e 100644 --- a/22 - Follow Along Link Highlighter/index-START.html +++ b/22 - Follow Along Link Highlighter/index-START.html @@ -26,8 +26,23 @@ - diff --git a/23 - Speech Synthesis/index-START.html b/23 - Speech Synthesis/index-START.html index e890008d36..4b9a0419a1 100644 --- a/23 - Speech Synthesis/index-START.html +++ b/23 - Speech Synthesis/index-START.html @@ -29,12 +29,41 @@

The Voiceinator 5000

diff --git a/24 - Sticky Nav/index-START.html b/24 - Sticky Nav/index-START.html index e7bc67e9a5..7c27a13a45 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..d53447804c 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; @@ -39,6 +43,11 @@ h1 { text-shadow: 3px 4px 0 rgba(0,0,0,0.2) } +.fixed-nav nav { + position: fixed; + box-shadow: 0 5px rgba(0, 0, 0, 0.1); +} + nav { background:black; top:0; @@ -72,6 +81,10 @@ li.logo { font-size: 30px; } +.fixed-nav li.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..d49e45b239 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,18 @@ diff --git a/26 - Stripe Follow Along Nav/index-START.html b/26 - Stripe Follow Along Nav/index-START.html index 9780d0d1ac..0f18d6a6d3 100644 --- a/26 - Stripe Follow Along Nav/index-START.html +++ b/26 - Stripe Follow Along Nav/index-START.html @@ -208,6 +208,38 @@

Cool

diff --git a/27 - Click and Drag/index-START.html b/27 - Click and Drag/index-START.html index b8609315f7..8307ce30e2 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 c4cbd4259a..88b91ca16f 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..d578b365cf 100644 --- a/29 - Countdown Timer/scripts-START.js +++ b/29 - Countdown Timer/scripts-START.js @@ -0,0 +1,49 @@ +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); + if (secondsLeft < 0) { + clearInterval(countdown); + return; + } + displayTimeLeft(secondsLeft); + displayEndTime(then); + }, 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 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, 10); + 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(); +}) diff --git a/30 - Whack A Mole/index-START.html b/30 - Whack A Mole/index-START.html index 2014ff458c..cad8544fa1 100644 --- a/30 - Whack A Mole/index-START.html +++ b/30 - Whack A Mole/index-START.html @@ -37,6 +37,54 @@

Whack-a-mole! 0

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(listHoles) { + const ind = Math.floor(Math.random() * listHoles.length) + const hole = listHoles[ind]; + 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(() => { + if (!timeUp) { + peep(); + } + hole.classList.remove('up'); + }, time); + } + + function startGame() { + scoreBoard.textContent = 0; + timeUp = false; + score = 0; + peep(); + setTimeout(() => (timeUp = true), 10000); + } + + function bonk(e) { + if (!e.isTrusted) { + return; + } + score++; + this.classList.remove('up'); + scoreBoard.textContent = score; + } + + moles.forEach(mole => mole.addEventListener('click', bonk));