diff --git a/01 - JavaScript Drum Kit/index-START.html b/01 - JavaScript Drum Kit/index-START.html index 4070d32767..17ae357965 100644 --- a/01 - JavaScript Drum Kit/index-START.html +++ b/01 - JavaScript Drum Kit/index-START.html @@ -58,7 +58,19 @@ diff --git a/02 - JS + CSS Clock/index-START.html b/02 - JS + CSS Clock/index-START.html index 2712384201..4c555c4762 100644 --- a/02 - JS + CSS Clock/index-START.html +++ b/02 - JS + CSS Clock/index-START.html @@ -18,7 +18,7 @@ diff --git a/03 - CSS Variables/index-START.html b/03 - CSS Variables/index-START.html index ca2b59d077..58be93389c 100644 --- a/03 - CSS Variables/index-START.html +++ b/03 - CSS Variables/index-START.html @@ -48,6 +48,27 @@

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..940f6592fc 100644 --- a/04 - Array Cardio Day 1/index-START.html +++ b/04 - Array Cardio Day 1/index-START.html @@ -31,29 +31,62 @@ // Array.prototype.filter() // 1. Filter the list of inventors for those who were born in the 1500's - + let result_1 = inventors.filter((person) => person.year >= 1500 && person.year < 1600) + console.table(result_1); + // Array.prototype.map() // 2. Give us an array of the inventors' first and last names + let result_2 = []; + inventors.map(person => {result_2.push(person.first + ' ' + person.last)}) + console.log(result_2); // Array.prototype.sort() // 3. Sort the inventors by birthdate, oldest to youngest + inventors.sort((a, b) => (- a.year + b.year)) + console.table(inventors); + // Array.prototype.reduce() // 4. How many years did all the inventors live? + // let total = 0; + // inventors.reduce((prePerson, curPerson, curIdx, src) => { + // total += (curPerson.passed - curPerson.year) + // }, 0) + // console.log(total); + const totalYears = inventors.reduce((total, inventor) => (total + (inventor.passed - inventor.year)), 0); + + console.log(totalYears); // 5. Sort the inventors by years lived + inventors.sort((a, b) => (-(a.passed - a.year) + (b.passed - b.year))) + console.table(inventors); // 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name // https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris + /* run the code in console of the wiki page*/ + // var result_6 = [...document.querySelectorAll('.mw-category a')].map(function(i){return i.innerHTML}); + // result_6.filter((n) => n.indexOf('de')>=0); // 7. sort Exercise // Sort the people alphabetically by last name + people.sort((a,b) => (a.split(',')[0].trim() > b.split(',')[0].trim() ? 1 : -1)); + console.log(people) // 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' ]; - + var result_8 = data.reduce((obj, item) => { + if(obj.hasOwnProperty(item)) { + obj[item] ++; + } + else { + obj[item] = 0; + } + return obj; + }, {}); + console.log(result_8); + diff --git a/05 - Flex Panel Gallery/index-START.html b/05 - Flex Panel Gallery/index-START.html index e1d643ad5c..c33e16bc0b 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,10 @@ font-size: 20px; background-size:cover; background-position:center; + flex: 1; + display: flex; + will-change: transform; + flex-direction: column; } @@ -61,13 +66,34 @@ font-family: 'Amatic SC', cursive; text-shadow:0 0 4px rgba(0, 0, 0, 0.72), 0 0 14px rgba(0, 0, 0, 0.45); font-size: 2em; + flex: 1; + align-items: center; + justify-content: center; + display: flex; + transition: transform .7s ease-in; } + .panel p:nth-child(1) { + transform: translateY(-100%); + } + .panel p:nth-child(3) { + transform: translateY(100%); + } + .panel p:nth-child(2) { font-size: 4em; } .panel.open { font-size:40px; + flex: 5; + } + + .panel.open p:nth-child(1) { + transform: translateY(0); + } + + .panel.open p:nth-child(3) { + transform: translateY(0); } .cta { @@ -107,10 +133,14 @@ - - diff --git a/06 - Type Ahead/index-START.html b/06 - Type Ahead/index-START.html index 1436886918..f40238790a 100644 --- a/06 - Type Ahead/index-START.html +++ b/06 - Type Ahead/index-START.html @@ -6,7 +6,7 @@ - +
- - + + diff --git a/07 - Array Cardio Day 2/index-START.html b/07 - Array Cardio Day 2/index-START.html index 969566ff78..b5c6b2a859 100644 --- a/07 - Array Cardio Day 2/index-START.html +++ b/07 - Array Cardio Day 2/index-START.html @@ -28,13 +28,29 @@ // Array.prototype.some() // is at least one person 19 or older? // Array.prototype.every() // is everyone 19 or older? + console.log('is at least one person 19 or older? The anwer is: ' + people.some(kid => (2017 - kid.year > 18))); + console.log('is everyone 19 or older? The anwer is: ' + people.every(kid => (2017 - kid.year > 18))); + // 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 txt = comments.find(comment => comment.id === 823423).text; + console.log(txt); // Array.prototype.findIndex() // Find the comment with this ID // delete the comment with the ID of 823423 + let idx = comments.findIndex(comment => comment.id === 823423); + console.log('the index of the id 823423 is ' + idx); + let comments_new = [ + ...comments.slice(0, idx), + ...comments.slice(idx + 1) + ] + + let newResult =[]; + comments_new.map(i => newResult.push(i.text)) + console.log('after delete it, the comments are [' + newResult.join(', ') +'] now'); + diff --git a/08 - Fun with HTML5 Canvas/index-START.html b/08 - Fun with HTML5 Canvas/index-START.html index 37c148df07..f9d2951200 100644 --- a/08 - Fun with HTML5 Canvas/index-START.html +++ b/08 - Fun with HTML5 Canvas/index-START.html @@ -14,6 +14,32 @@ margin:0; } + diff --git a/09 - Dev Tools Domination/index-START.html b/09 - Dev Tools Domination/index-START.html index 196fffd719..a3fbf31cae 100644 --- a/09 - Dev Tools Domination/index-START.html +++ b/09 - Dev Tools Domination/index-START.html @@ -18,28 +18,52 @@ } // Regular + console.log('haha') // Interpolated - + console.log('hello %s', 'shit'); + // Styled + console.log('%c hello shit', 'font-size: 20px;color: red'); // warning! + console.warn('haha') // Error :| + console.error('haha') // Info - + console.info('haha') // Testing + console.assert(1 === 2, 'that\'s wrong') // clearing + // console.clear(); // Viewing DOM Elements - + console.dir(document.querySelector('p')); // Grouping together + dogs.forEach(dog => { + console.group(`${dog.name}`) + console.log(`this is ${dog.name}`) + console.log(`I'm ${dog.age} years old`) + console.groupEnd(`${dog.name}`) + }) // counting + console.count('shit') + console.count('shit') + console.count('shit') + console.count('shit') // timing + console.time('fetching'); + fetch('https://api.github.com/users/saury') + .then(data => data.json()) + .then(data => { + console.timeEnd('fetching'); + console.log(data); + }); diff --git a/10 - Hold Shift and Check Checkboxes/index-START.html b/10 - Hold Shift and Check Checkboxes/index-START.html index eb7ed310bb..652de71414 100644 --- a/10 - Hold Shift and Check Checkboxes/index-START.html +++ b/10 - Hold Shift and Check Checkboxes/index-START.html @@ -104,6 +104,35 @@ diff --git a/11 - Custom Video Player/index.html b/11 - Custom Video Player/index.html index 281a15eaa8..8312bb5de9 100644 --- a/11 - Custom Video Player/index.html +++ b/11 - Custom Video Player/index.html @@ -8,7 +8,7 @@
- +
diff --git a/11 - Custom Video Player/scripts.js b/11 - Custom Video Player/scripts.js index e69de29bb2..6d611afce6 100644 --- a/11 - Custom Video Player/scripts.js +++ b/11 - Custom Video Player/scripts.js @@ -0,0 +1,17 @@ +const vdo = document.querySelector('.player__video'); +let vdo_play = false; +vdo.addEventListener('canplay', canPlay, false); + +function canPlay() { + document.querySelector('.player__button') + .addEventListener('click', e => { + if(!vdo_play){ + vdo.play(); + vdo_play = true; + } + else{ + vdo.pause(); + vdo_play = false; + } + }, false) +} \ No newline at end of file diff --git a/12 - Key Sequence Detection/index-START.html b/12 - Key Sequence Detection/index-START.html index 8cab786140..bece7e4862 100644 --- a/12 - Key Sequence Detection/index-START.html +++ b/12 - Key Sequence Detection/index-START.html @@ -6,7 +6,16 @@ +

TYPE: 'wesbos' to active the gifs

diff --git a/13 - Slide in on Scroll/index-START.html b/13 - Slide in on Scroll/index-START.html index 0b9fb8fccb..794854d25b 100644 --- a/13 - Slide in on Scroll/index-START.html +++ b/13 - Slide in on Scroll/index-START.html @@ -58,6 +58,28 @@

Slide in on Scroll

}; } + window.onload = function() { + var imgInfo = []; + + [...document.querySelectorAll('img')].forEach((ele, idx) => { + imgInfo.push({ + 'dom': ele, + 'top': ele.offsetTop, + 'height': ele.offsetHeight + }) + }) + + window.addEventListener('scroll', e => { + imgInfo.forEach((info, idx) => { + if(((window.scrollY) >= (info.top + .5 * info.height - window.innerHeight)) && ((window.scrollY) <= (info.top + 1.5 * info.height - .5 * window.innerHeight))){ + (info.dom).classList.add('active') + } + else { + (info.dom).classList.remove('active') + } + }) + }) + } diff --git a/17 - Sort Without Articles/index-START.html b/17 - Sort Without Articles/index-START.html index cfaf3e0440..6ba1eb510b 100644 --- a/17 - Sort Without Articles/index-START.html +++ b/17 - Sort Without Articles/index-START.html @@ -9,7 +9,7 @@ diff --git a/22 - Follow Along Link Highlighter/index-START.html b/22 - Follow Along Link Highlighter/index-START.html index 8476112b5e..659085b6d1 100644 --- a/22 - Follow Along Link Highlighter/index-START.html +++ b/22 - Follow Along Link Highlighter/index-START.html @@ -24,9 +24,27 @@

Esse quibusdam, ad, ducimus cupiditate nulla, quae magni odit totam ut consequatur eveniet sunt quam provident sapiente dicta neque quod.

Aliquam dicta sequi culpa fugiat consequuntur pariatur optio ad minima, maxime odio, distinctio magni impedit tempore enim repellendus repudiandae quas!

- diff --git a/23 - Speech Synthesis/index-START.html b/23 - Speech Synthesis/index-START.html index e890008d36..5209066e7a 100644 --- a/23 - Speech Synthesis/index-START.html +++ b/23 - Speech Synthesis/index-START.html @@ -29,12 +29,40 @@

The Voiceinator 5000

diff --git a/24 - Sticky Nav/index-START.html b/24 - Sticky Nav/index-START.html index e7bc67e9a5..78b0719011 100644 --- a/24 - Sticky Nav/index-START.html +++ b/24 - Sticky Nav/index-START.html @@ -54,7 +54,14 @@

A story about getting lost.

diff --git a/24 - Sticky Nav/style-START.css b/24 - Sticky Nav/style-START.css index c6d59a31b3..52c838fb75 100644 --- a/24 - Sticky Nav/style-START.css +++ b/24 - Sticky Nav/style-START.css @@ -84,3 +84,18 @@ nav a { transition:all 0.2s; text-transform: uppercase; } + +nav.affix-top { + position: fixed; + top: 0; + left: 0; + right: 0; +} +nav.affix-top li.logo{ + max-width: 210px; +} + +nav.affix-top + .site-wrap{ + transform: scale(1); + margin-top: 146px; +} \ No newline at end of file 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..be240c3f5b 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,19 @@ diff --git a/26 - Stripe Follow Along Nav/index-START.html b/26 - Stripe Follow Along Nav/index-START.html index 9780d0d1ac..4a52d97897 100644 --- a/26 - Stripe Follow Along Nav/index-START.html +++ b/26 - Stripe Follow Along Nav/index-START.html @@ -208,6 +208,27 @@

Cool

diff --git a/27 - Click and Drag/index-START.html b/27 - Click and Drag/index-START.html index b8609315f7..4c3cc59d15 100644 --- a/27 - Click and Drag/index-START.html +++ b/27 - Click and Drag/index-START.html @@ -35,6 +35,36 @@ diff --git a/29 - Countdown Timer/scripts-START.js b/29 - Countdown Timer/scripts-START.js index e69de29bb2..ee9286e912 100644 --- a/29 - Countdown Timer/scripts-START.js +++ b/29 - Countdown Timer/scripts-START.js @@ -0,0 +1,32 @@ +let $$ = (target, context) => (context || document).querySelectorAll(target); +let timerInterval; +let updateDisplay = sec => { + clearInterval(timerInterval); + $$('.display__time-left')[0].innerHTML = ''; + $$('.display__end-time')[0].innerHTML = ''; + timerInterval = setInterval(()=>{ + if(sec<=0) clearInterval(timerInterval); + let current = new Date(); + let h = Math.floor(sec / 3600); + let m = Math.floor(sec % 3600 / 60); + let s = sec % 60; + let fm = (current.getMinutes() + m) % 60; + let fh = (current.getHours() + Math.floor((current.getMinutes() + m) / 60)) % 24; + document.title = `${h} : ${m} : ${s}`; + $$('.display__time-left')[0].innerHTML = `${h} : ${m} : ${s}`; + $$('.display__end-time')[0].innerHTML = `${fh} : ${fm}`; + sec--; + }, 1000) +} + +[].forEach.call($$('.timer__button'), function(ele) { + ele.addEventListener('click', e => { + updateDisplay(Number(ele.getAttribute('data-time'))); + }, false) +}) + +document.customForm.addEventListener('submit', function(e) { + e.preventDefault(); + const _secs = this.minutes.value * 60; + updateDisplay(_secs); +}); \ No newline at end of file diff --git a/readme.md b/readme.md index 5a1eaa18c8..2a45dd0a26 100644 --- a/readme.md +++ b/readme.md @@ -1,17 +1,36 @@ -![](https://javascript30.com/images/JS3-social-share.png) - # JavaScript30 -Starter Files + Completed solutions for the JavaScript 30 Day Challenge. - -Grab the course at [https://JavaScript30.com](https://JavaScript30.com) - -Text-based guides (unofficial) for the challenges can be found here - [Text Guides](https://github.com/nitishdayal/JavaScript30). - -## Pull Requests - -These are meant to be 1:1 copies of what is done in the video. If you found a better / different way to do things, great, but I will be keeping them the same as the videos. - -The starter files + solutions will be updated if/when the videos are updated. - -Thanks! +> Course [JavaScript30](https://javascript30.com) created by [Wes Bos](https://github.com/wesbos) + +> Folked repo for practice and fun! + +1. [x] ~~JavaScript Drum Kit~~ +2. [x] ~~JS + CSS Clock~~ +3. [x] ~~CSS Variables~~ +4. [x] ~~Array Cardio, Day 1~~ +5. [x] ~~Flex Panel Gallery~~ +6. [x] ~~Type Ahead~~ +7. [x] ~~Array Cardio, Day 2~~ +8. [x] ~~Fun with HTML5 Canvas~~ +9. [x] ~~Dev Tools Domination~~ +10. [x] ~~Hold Shift and Check Checkboxes~~ +11. [x] ~~Custom Video Player~~ +12. [x] ~~Key Sequence Detection~~ +13. [x] ~~Slide in on Scroll~~ +14. [x] ~~JavaScript References vs. Copying~~ +15. [x] ~~LocalStorage~~ +16. [x] ~~Mouse Move Shadow~~ +17. [x] ~~Sort Without Articles~~ +18. [x] ~~Adding Up Times with Reduce~~ +19. [x] ~~Webcam Fun~~ +20. [x] ~~Speech Detection~~ +21. [x] ~~Geolocation~~ +22. [x] ~~Follow Along Link Highlighter~~ +23. [x] ~~Speech Synthesis~~ +24. [x] ~~Sticky Nav~~ +25. [x] ~~Event Capture, Propagation, Bubbling, and Once~~ +26. [x] ~~Stripe Follow Along Nav~~ +27. [x] ~~Click and Drag~~ +28. [ ] Video Speed Controller +29. [x] ~~Countdown Timer~~ +30. [ ] Whack A Mole \ No newline at end of file