From f78d3d7c68373077542bb298bf5c4b1288d8b045 Mon Sep 17 00:00:00 2001 From: herron9 Date: Wed, 5 Aug 2020 17:17:39 -0700 Subject: [PATCH 01/29] Day 1 summary --- 01 - JavaScript Drum Kit/README.md | 38 +++++++++++++++++++++++ 01 - JavaScript Drum Kit/index-START.html | 26 ++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 01 - JavaScript Drum Kit/README.md diff --git a/01 - JavaScript Drum Kit/README.md b/01 - JavaScript Drum Kit/README.md new file mode 100644 index 0000000000..9e1ac9cab1 --- /dev/null +++ b/01 - JavaScript Drum Kit/README.md @@ -0,0 +1,38 @@ +#ReadMe + +##Knowledge + +###1. Document method `Document.querySelector()` +https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector +> The Document method `querySelector()` returns the first `Element` within the document that matches the specified selector, or group of selectors. If no matches are found, null is returned. + +###2. CSS Attribute selector +https://www.w3schools.com/cssref/css_selectors.asp + +CSS selector works in the same way in JavaScript: + +| Selector | Example | Example description | +|---|---|---| +| `[attribute=value]` | `[target=_blank]` | Selects all elements with target="_blank" + +###3. Audio `play()` Method +https://www.w3schools.com/jsref/met_audio_play.asp + +####3.1 HTML Audio/Video DOM `currentTime` Property +```JavaScript +var vid = document.getElementById("myVideo"); +vid.currentTime = 5; +``` +> The currentTime property sets or returns the current position (in seconds) of the audio/video playback. + +###4. `Element.classList` +https://developer.mozilla.org/en-US/docs/Web/API/Element/classList +>The `Element.classList` is a read-only property that returns a live `DOMTokenList` collection of the class attributes of the element. **This can then be used to manipulate the class list**. + +>Using `classList` is a convenient alternative to accessing an element's list of classes as a space-delimited string via `element.className`. + +###5. HTMLElement: `transitionend event` +https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/transitionend_event + +>The `transitionen` event is fired when a CSS transition has completed. In the case where a transition is removed before completion, such as if the `transition-property` is removed or `display` is set to none, then the event will not be generated. + diff --git a/01 - JavaScript Drum Kit/index-START.html b/01 - JavaScript Drum Kit/index-START.html index 4070d32767..898c714e74 100644 --- a/01 - JavaScript Drum Kit/index-START.html +++ b/01 - JavaScript Drum Kit/index-START.html @@ -59,6 +59,32 @@ From b838a18a73b7ea1f2d561a3abc69906fc389ffa9 Mon Sep 17 00:00:00 2001 From: herong Date: Wed, 5 Aug 2020 17:22:01 -0700 Subject: [PATCH 02/29] Update README.md --- 01 - JavaScript Drum Kit/README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/01 - JavaScript Drum Kit/README.md b/01 - JavaScript Drum Kit/README.md index 9e1ac9cab1..fcc82f93e8 100644 --- a/01 - JavaScript Drum Kit/README.md +++ b/01 - JavaScript Drum Kit/README.md @@ -1,12 +1,12 @@ -#ReadMe +# ReadMe -##Knowledge +## Knowledge ###1. Document method `Document.querySelector()` https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector > The Document method `querySelector()` returns the first `Element` within the document that matches the specified selector, or group of selectors. If no matches are found, null is returned. -###2. CSS Attribute selector +### 2. CSS Attribute selector https://www.w3schools.com/cssref/css_selectors.asp CSS selector works in the same way in JavaScript: @@ -15,23 +15,23 @@ CSS selector works in the same way in JavaScript: |---|---|---| | `[attribute=value]` | `[target=_blank]` | Selects all elements with target="_blank" -###3. Audio `play()` Method +### 3. Audio `play()` Method https://www.w3schools.com/jsref/met_audio_play.asp -####3.1 HTML Audio/Video DOM `currentTime` Property +#### 3.1 HTML Audio/Video DOM `currentTime` Property ```JavaScript var vid = document.getElementById("myVideo"); vid.currentTime = 5; ``` > The currentTime property sets or returns the current position (in seconds) of the audio/video playback. -###4. `Element.classList` +### 4. `Element.classList` https://developer.mozilla.org/en-US/docs/Web/API/Element/classList >The `Element.classList` is a read-only property that returns a live `DOMTokenList` collection of the class attributes of the element. **This can then be used to manipulate the class list**. >Using `classList` is a convenient alternative to accessing an element's list of classes as a space-delimited string via `element.className`. -###5. HTMLElement: `transitionend event` +### 5. HTMLElement: `transitionend event` https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/transitionend_event >The `transitionen` event is fired when a CSS transition has completed. In the case where a transition is removed before completion, such as if the `transition-property` is removed or `display` is set to none, then the event will not be generated. From 82a39a0e90cf017d08baa2f7a5393d9579074dc1 Mon Sep 17 00:00:00 2001 From: herong Date: Wed, 5 Aug 2020 17:22:23 -0700 Subject: [PATCH 03/29] Update README.md --- 01 - JavaScript Drum Kit/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/01 - JavaScript Drum Kit/README.md b/01 - JavaScript Drum Kit/README.md index fcc82f93e8..6f87d67e62 100644 --- a/01 - JavaScript Drum Kit/README.md +++ b/01 - JavaScript Drum Kit/README.md @@ -2,7 +2,7 @@ ## Knowledge -###1. Document method `Document.querySelector()` +### 1. Document method `Document.querySelector()` https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector > The Document method `querySelector()` returns the first `Element` within the document that matches the specified selector, or group of selectors. If no matches are found, null is returned. From b522e560b335fa3ba07a1ddf8f8de8add4abc371 Mon Sep 17 00:00:00 2001 From: herron9 Date: Thu, 6 Aug 2020 15:58:15 -0700 Subject: [PATCH 04/29] Day 2 - CSS + JS Clock --- .tern-project | 12 +++++ 02 - JS and CSS Clock/README.md | 9 ++++ 02 - JS and CSS Clock/index-START.html | 27 ++++++++++- readme.md | 66 +------------------------- 4 files changed, 49 insertions(+), 65 deletions(-) create mode 100644 .tern-project create mode 100644 02 - JS and CSS Clock/README.md diff --git a/.tern-project b/.tern-project new file mode 100644 index 0000000000..0a2f08812f --- /dev/null +++ b/.tern-project @@ -0,0 +1,12 @@ +{ + "libs": [ + "browser" + ], + "plugins": { + "node": {}, + "modules": {}, + "requirejs": {}, + "es_modules": {}, + "jasmine": {} + } +} \ No newline at end of file diff --git a/02 - JS and CSS Clock/README.md b/02 - JS and CSS Clock/README.md new file mode 100644 index 0000000000..1b90f7b134 --- /dev/null +++ b/02 - JS and CSS Clock/README.md @@ -0,0 +1,9 @@ +# Knowledge + +## 1. `transform-origin` CSS property + +https://developer.mozilla.org/en-US/docs/Web/CSS/transform-origin + +> The `transform-origin` CSS property sets the origin for an element's transformations. + +100% along the x-axis will put that pivot point on the very right-hand side. diff --git a/02 - JS and CSS Clock/index-START.html b/02 - JS and CSS Clock/index-START.html index 7a6d27d5bd..5568ee9897 100644 --- a/02 - JS and CSS Clock/index-START.html +++ b/02 - JS and CSS Clock/index-START.html @@ -62,12 +62,37 @@ background: black; position: absolute; top: 50%; + /* move pviot to right end */ + transform-origin: 100%; + transform: rotate(90deg); + transition: all 0.05s; + /* how it moves */ + transition-timing-function: cubic-bezier(0.1, 2.7, 0.58, 1); + } - diff --git a/readme.md b/readme.md index 73d2f28303..b346908efe 100644 --- a/readme.md +++ b/readme.md @@ -6,69 +6,7 @@ Starter Files + Completed solutions for the JavaScript 30 Day Challenge. Grab the course at [https://JavaScript30.com](https://JavaScript30.com) -## Community #JavaScript30 Content +## Note -Feel free to submit a PR adding a link to your own recaps, guides or reviews! +This's Herong's notebook for JavaScript30 lesson. -* [Arjun Khode’s blog](http://thesagittariusme.blogspot.com/search/label/JS30) about summaries for each day, including fixed glitches, bugs and extra features -* [Nitish Dayal's Text Guides](https://github.com/nitishdayal/JavaScript30) are great for those who like reading over watching -* [Meredith Underell's](http://meredithunderell.com/tag/javascript30/) Quick Lessons Learned -* [Rowan Weismiller's](http://rowanweismiller.com/blog/javascript-30/) Recaps + Lessons Learned -* [Thorsten Frommen](https://tfrommen.de/tag/javascript-30/) shares how he solved the exercises before viewing the answers -* [Soyaine 写的中文指南](https://github.com/soyaine/JavaScript30)包含了过程记录和难点解释 -* [Ayo Isaiah's](https://freshman.tech/archive/#javascript30) Recaps and Lessons Learned -* [Adriana Rios](https://stpcollabr8nlstn.github.io/JavaScript30/) shares her alternative solutions -* [Michael Einsohn](http://30daysofjs.michaeleinsohn.com) publishes each challenge after watching the video once -* [Mike Ekkel](https://medium.com/@mike_ekkel/javascript-30-a-30-day-vanilla-js-challenge-6a733fc9f62c#.9frjtaje9) -* [Yusef Habib](https://github.com/yhabib/JavaScript30) lessons and tricks learned, and a [gh-page](https://yhabib.github.io/JavaScript30/) to see working all the mini-projects. -* [Amelie Yeh](https://github.com/amelieyeh/JS30) 30 lessons notes with things I've learned, and those important recaps. and directly view my demos [here](https://amelieyeh.github.io/JS30/) 🇹🇼😄 -* [Winar](https://github.com/winar-jin/JavaScript30-Challenge)的JavaScript30天挑战,记录练习过程,重难点和其他的解决方案。🎨 -* [Rayhatron](https://rayhatron.github.io/blog/) - walkthroughs, recaps and lessons learned. -* [Andrei Dobra](https://github.com/andreidbr/JS30) Full repo with lessons learned and a [gh-page](https://andreidbr.github.io/JS30/) with all the exercises. -* [从零到壹全栈部落](https://github.com/liyuechun/JavaScript30-liyuechun),春哥发起的从零到壹全栈部落,旨在带领大家一起学习,一起输出,文档化,代码化,中文视频化,全栈部落口号:输出是最好的学习方式。 -* [Usmaan Ali's](https://github.com/usyyy/javascript/blob/master/JavaScript30/analysis.md) summary of the technical skills learned from each project. He's also posting them as separate blog posts [here](https://medium.com/@usyyy) -* [Axel](https://github.com/afuh/js30)'s lessons learned and a [showcase](https://afuh.github.io/js30/) with the projects. -* [Chris](https://github.com/dwatow/JavaScript30) 中文實戰,目標描述、過程紀錄。 -* [Muhammad D. Ramadhan's](https://miayam.github.io) blog. He shamlesly mixed his personal life with 30 day JavaScript challenge so as to increase his learning retention. He also summarised the challenge on [one single page](https://miayam.github.io/js30). Do not read his blog! -* [Lee Keitel's Blog](https://blog.keitel.xyz/categories/javascript30/) includes summaries of each lesson, what I learned from each one, and my thoughts about the topic taught and using them in the future. -* [Dustin Hsiao](https://github.com/dustinhsiao21/Javascript30-dustin) 包含了各篇介紹、 效果Demo、各篇詳解及記錄過程,附上部分延伸閱讀及[gh-page](https://dustinhsiao21.github.io/Javascript30-dustin/)。 -* [GuaHsu](https://github.com/guahsu/JavaScript30) - 紀錄各篇練習過程與心得,並嘗試擴充部分練習,也做了一個包含全部練習的[介紹站](http://guahsu.io/JavaScript30/)🇹🇼 -* [Daniela](https://github.com/misslild)'s completed challenges on [GitHub Pages](https://misslild.github.io/WesBos-30day-Coding-challenge/) and [Codepen](https://codepen.io/collection/DapZeP/) :raised_hands: :muscle: :+1: -* [Dmitrii Pashutskii's](https://github.com/guar47) code of all challenges on [GitHub with Pages](https://github.com/guar47/javascript30Summary) and review [blog posts](https://blog.dpashutskii.com/tag/javascript30/) -* [Abid Hasan's](https://github.com/sabidhasan/javascript-30) completion of all challenges. This was awesome!! Learned so much! :+1: -* [Yusong Notes](https://sky172839465.github.io/course/js30) Records Yusong JS 30 days note and demo :star2: -* [Ding's Implementation](https://github.com/Ding-Fan/javascript30) code and online demo -* [Herminio Torres](https://github.com/herminiotorres/JavaScript30) lessons and tricks learned, and a [gh-page](https://herminiotorres.github.io/JavaScript30/) to see working all the mini-projects. -* [Dmytro Borysovskyi](https://github.com/dimabory) says many thanks to for the course to Wes 🤝 It was incredible challenge 👌 The full repository with code available [here](https://github.com/dimabory/dimabory.github.io/tree/gh-pages/src/components/JavaScript30Days) and demos can be reached by the link to [gh-pages](https://dimabory.github.io/#/js30days) 👍👍👍 -* [Kizito](https://github.com/akhilome/)'s follow along [repo](https://github.com/akhilome/js30) with [completed challenges](https://akhilome.github.io/js30) and [notes](https://akhilome.github.io/js30/notes). -* [VannTile](https://github.com/vanntile)'s [repository](https://github.com/vanntile/JavaScript30) and [GitHub Pages showcase](https://vanntile.github.io/JavaScript30/). Thank you for a great ⌨️ experience. -* [Alex Kim](https://github.com/Alex-K1m/js30-challenge) completed all the challenges. You can check them out at [github pages](https://alex-k1m.github.io/js30-challenge/). -* [Mikhail Thomas](https://github.com/seckela) created [JS30++](https://github.com/seckela/js30plusplus) to add another level of challenge ontop of this already great course. -* [Ramon Morcillo](https://github.com/reymon359/JavaScript30) finished this awesome challenge!. You can see the showcase of his implementations on [this link](https://reymon359.github.io/JavaScript30/). -* [Santiago Escobar](https://github.com/sescobar99)'s [repository](https://github.com/sescobar99/javascript30-challenge) and [GitHub Pages showcase](https://sescobar99.github.io/javascript30-challenge/). -* [Harry Xie](https://github.com/a90100/JavaScript30) 紀錄 30 天的練習筆記在 [此連結](https://github.com/a90100/JavaScript30). -* [ Van Ribeiro's ](https://vanribeiro-30daysofjavascript.netlify.app/) about demos and recaps. On [GitHub Repo](https://github.com/vanribeiro/30days-Of-JavaScript) there's a summary about what was learned and researched. -* [Mugilan](https://github.com/Mugilan-Codes) is currently doing this challenge. Check out his [Repo](https://github.com/Mugilan-Codes/javascript-30) and the [Live Demo](https://mugilan-codes.github.io/javascript-30/). -* [Eshan Vohra](https://github.com/eshanvohra) is currently doing this challenge. Check out my repo [here](https://github.com/eshanvohra/JavaScript30). -* [RegusAl](https://github.com/RegusAl) is currently doing this challenge. Check out my repo [here](https://github.com/RegusAl/JavaScript30). - - -## Alternative Implementations -Here are some links of people who have done the tutorials, but in a different language or framework: - -* [Thomas Mattacchione](https://github.com/tkjone/clojurescript-30) JavaScript 30 written in ClojureScript -* [Dave Follett's](https://github.com/davefollett) blog series, [A New Vue on #JavaScript30](https://davefollett.io/categories/a-new-vue-on-javascript30/), where he explores re-implementing #JavaScript30 projects using [Vue](https://vuejs.org). -* [Akinjide Bankole](https://github.com/akinjide/JS30days) used Node.js with [Jade](http://jadelang.net) to solve the exercises -* [Adrien Poly](https://github.com/adrienpoly/javascript30-stimulus) a modest attempt to convert Drum Kit, Video Player, Local Tapas, TypeHead to [Stimulus JS](https://stimulusjs.org/) framework in a Rails App. -* [Bogdan Lazar](https://github.com/tricinel/TypeScript30) all the JavaScript 30 written in [TypeScript](https://www.typescriptlang.org/) -* [Will Wager](https://github.com/wwags33/JavaScript30) another [TypeScript](https://www.typescriptlang.org/) implementation! -* [marcoSven](https://github.com/marcoSven) solution suggestion for [10 - Hold Shift and Check Checkboxes](https://github.com/marcoSven/JavaScript30/blob/master/10%20-%20Hold%20Shift%20and%20Check%20Checkboxes/index-FINISHED.html) -* [ALMaclaine](https://github.com/almaclaine) Javascript 30 written in [Dart 2.0](https://github.com/ALMaclaine/Dart30). - -## A note on 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! From 69ba9812d121c2a319f9ab262a61487a1357d311 Mon Sep 17 00:00:00 2001 From: herron9 Date: Thu, 6 Aug 2020 17:02:23 -0700 Subject: [PATCH 05/29] Day 3 - Update Css Variables with JS --- 03 - CSS Variables/README.md | 11 +++++++++ 03 - CSS Variables/index-START.html | 38 ++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 03 - CSS Variables/README.md diff --git a/03 - CSS Variables/README.md b/03 - CSS Variables/README.md new file mode 100644 index 0000000000..f8603ab5bf --- /dev/null +++ b/03 - CSS Variables/README.md @@ -0,0 +1,11 @@ +# Knowledge + +## 1. Update CSS Variables with JS + +When you change a variable in CSS, everywhere on the page that the avriable is refernced will update itself. + +## 2. Using CSS custom properties (variables) + +https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties + +> **Custom properties** (sometimes referred to as CSS variables or cascading variables) are entities defined by CSS authors that contain specific values to be reused throughout a document. They are set using custom property notation (e.g., `--main-color: black;`) and are accessed using the var() function (e.g., color: `var(--main-color);`). \ No newline at end of file diff --git a/03 - CSS Variables/index-START.html b/03 - CSS Variables/index-START.html index 6b9b539c09..5625c0e0c0 100644 --- a/03 - CSS Variables/index-START.html +++ b/03 - CSS Variables/index-START.html @@ -12,6 +12,7 @@

Update CSS Variables with JS

+ @@ -21,8 +22,23 @@

Update CSS Variables with JS

From fe5d3a5081bf211c3299f7bbbdb1f2b355af4dcb Mon Sep 17 00:00:00 2001 From: herron9 Date: Thu, 6 Aug 2020 18:30:17 -0700 Subject: [PATCH 06/29] Day 4 - Array Cardio Day 2 --- 04 - Array Cardio Day 1/index-START.html | 56 +++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/04 - Array Cardio Day 1/index-START.html b/04 - Array Cardio Day 1/index-START.html index d19181b6b4..060a524772 100644 --- a/04 - Array Cardio Day 1/index-START.html +++ b/04 - Array Cardio Day 1/index-START.html @@ -31,28 +31,82 @@ // Array.prototype.filter() // 1. Filter the list of inventors for those who were born in the 1500's + const fifteen = inventors.filter(function(inventor) { + if (inventor.year >= 1500 && inventor.year < 1600) { + return true; + } + }); + + const fifteen2 = inventors.filter(inventor => inventor.year >= 1500 && inventor.year < 1600); + + console.table(fifteen); + console.table(fifteen2); // Array.prototype.map() // 2. Give us an array of the inventors first and last names + const map = inventors.map(inventor => `${inventor.first}` +` ${inventor.last}`); + console.log(map); // Array.prototype.sort() // 3. Sort the inventors by birthdate, oldest to youngest + const sortArray = inventors.sort((x, y) => x.year - y.year); + + const sortArray2 = inventors.sort((x, y) => x.year > y.year ? 1 : -1); + console.table(sortArray); + console.table(sortArray2); // Array.prototype.reduce() // 4. How many years did all the inventors live all together? + const totalAge = inventors.reduce( + (total, inventor) => (inventor.passed - inventor.year + total), 0) ; + console.log(totalAge); // 5. Sort the inventors by years lived + const sortByAgeArray = inventors.sort((x, y) => { + const xAge = x.passed - x.year; + const yAge = y.passed - y.year; + return xAge > yAge ? -1 : 1; + }); + console.table(sortByAgeArray); // 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 list = document.querySelector('.mw-category'); + // convert to array option 1 + // const links = Array.from(list.querySelectorAll('a')); + // option 2: + // const links = [...list.querySelectorAll('a')]; + // no map() under NodeList so this will not work unless you convert it to array. + // const boulevards = links.map(link => link.textContent); + // const de = boulevards.filter(blvd => blvd.includes('de')); + + // console.log(de); // 7. sort Exercise // Sort the people alphabetically by last name + const sortNameArray = people.sort((x, y) => { + const xLast = x.split(',')[0]; + const yLast = y.split(',')[0]; + + return xLast < yLast ? -1 : 1; + }); + + console.log(sortNameArray); // 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 data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ]; + + // start with an empty object + const result = data.reduce((obj, item) => { + if (!obj[item]) { + obj[item] = 0; + } + obj[item]++; + return obj; + }, {}); + console.log(result); From 2d385dc308329c560195a9b08280189fb5d493b7 Mon Sep 17 00:00:00 2001 From: herron9 Date: Fri, 7 Aug 2020 16:45:30 -0700 Subject: [PATCH 07/29] Day 5 Flex Panels Image Gallery --- 05 - Flex Panel Gallery/README.md | 11 +++++ 05 - Flex Panel Gallery/index-START.html | 61 +++++++++++++++++++++++- 2 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 05 - Flex Panel Gallery/README.md diff --git a/05 - Flex Panel Gallery/README.md b/05 - Flex Panel Gallery/README.md new file mode 100644 index 0000000000..6611b51e1f --- /dev/null +++ b/05 - Flex Panel Gallery/README.md @@ -0,0 +1,11 @@ +# Knowledge + +## 1. CSS flexbox layout + +https://css-tricks.com/snippets/css/a-guide-to-flexbox/ + +## 2. `DOMTokenList.toggle()` + +https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList/toggle + +> The `toggle()` method of the `DOMTokenList` interface removes a given `token` from the list and returns `false`. If token doesn't exist it's added and the function returns `true`. \ No newline at end of file diff --git a/05 - Flex Panel Gallery/index-START.html b/05 - Flex Panel Gallery/index-START.html index 71d1c26f00..f3a0dee950 100644 --- a/05 - Flex Panel Gallery/index-START.html +++ b/05 - Flex Panel Gallery/index-START.html @@ -26,6 +26,8 @@ .panels { min-height: 100vh; overflow: hidden; + /* Make it a flex item */ + display: flex; } .panel { @@ -43,6 +45,14 @@ font-size: 20px; background-size: cover; background-position: center; + /* Evenly distribute the extra space among each other*/ + flex: 1; + justify-content: center; + align-items: center; + /* Make it a flex container as well */ + display: flex; + /* Vertically center them in the middle */ + flex-direction: column; } .panel1 { background-image:url(https://source.unsplash.com/gYl-UtwNg_I/1500x1500); } @@ -52,10 +62,36 @@ .panel5 { background-image:url(https://source.unsplash.com/3MNzGlQM7qs/1500x1500); } /* Flex Children */ + /* Children element in each panel */ .panel > * { margin: 0; width: 100%; transition: transform 0.5s; + border: 1px solid red; + flex: 1 0 auto; + /* Make each children elements a flex container */ + display: flex; + /* Center text */ + justify-content: center; + align-items: center; + } + + /* Take out upper element */ + .panel > *:first-child { + transform: translateY(-100%); + } + + .panel.open-active > *:first-child { + transform: translateY(0); + } + + /* Take out lower element */ + .panel > *:last-child { + transform: translateY(100%); + } + + .panel.open-active > *:last-child { + transform: translateY(0); } .panel p { @@ -71,6 +107,8 @@ .panel.open { font-size: 40px; + /* This element will expand to 5 times of other item's space (1) when triggered */ + flex: 5; } @@ -96,7 +134,7 @@

Give

All

You can

- +

Life

In

@@ -105,9 +143,28 @@
+ function toggleOpen() { + // Add open class + this.classList.toggle('open'); + } + panels.forEach(panel => panel.addEventListener('transitionend', showWords)); + + function showWords(e) { + // this will be flex-grow and font-size in Chrome, but flex in Safari + // console.log(e.propertyName); + if (e.propertyName.includes('flex')) { + this.classList.toggle('open-active'); + } + } + + From 2175d105e4a56531103545c8f56d40fc27ec1327 Mon Sep 17 00:00:00 2001 From: herron9 Date: Tue, 11 Aug 2020 16:26:51 -0700 Subject: [PATCH 08/29] Day 6 - Ajax type Ahead --- 06 - Type Ahead/README.md | 32 ++++++++++++++++++++ 06 - Type Ahead/index-START.html | 51 ++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 06 - Type Ahead/README.md diff --git a/06 - Type Ahead/README.md b/06 - Type Ahead/README.md new file mode 100644 index 0000000000..95bceb7cf8 --- /dev/null +++ b/06 - Type Ahead/README.md @@ -0,0 +1,32 @@ +# Knowledge +## 1. spread / rest operator `...` +https://dev.to/sagar/three-dots---in-javascript-26ci + +### Spread Operators +> The spread operator is used to expand elements of an iterable (like an array) into places where multiple elements can fit. + +```JavaScript +const featured = ['Deep Dish', 'Pepperoni', 'Hawaiian']; +const specialty = ['Meatzza', 'Spicy Mama', 'Margherita']; + +const pizzas = [...featured, 'veg pizza', ...specialty]; +// 'Deep Dish', 'Pepperoni', 'Hawaiian', 'veg pizza', 'Meatzza', 'Spicy Mama', 'Margherita' +console.log(pizzas); +``` + +### Rest Parameters +> With rest parameters, we can gather any number of arguments into an array and do what we want with them. Rest parameters have been introduced to reduce the boilerplate code that was induced by the arguments. + + +## 2. HTML DOM Events +https://www.w3schools.com/jsref/dom_obj_event.asp +> HTML DOM events allow JavaScript to register different event handlers on elements in an HTML document. +> Events are normally used in combination with functions, and the function will not be executed before the event occurs (such as when a user clicks a button). + +## 3. HTML DOM innerHTML Property +https://www.w3schools.com/jsref/prop_html_innerhtml.asp +> The innerHTML property sets or returns the HTML content (inner HTML) of an element. + +```JavaScript +document.getElementById("demo").innerHTML = "Paragraph changed!"; +``` \ No newline at end of file diff --git a/06 - Type Ahead/index-START.html b/06 - Type Ahead/index-START.html index 109c90fb36..0c1d7055b9 100644 --- a/06 - Type Ahead/index-START.html +++ b/06 - Type Ahead/index-START.html @@ -17,6 +17,57 @@ From 0670fcfe65d7de7e06dfcf011743d9d0941b948d Mon Sep 17 00:00:00 2001 From: herron9 Date: Tue, 11 Aug 2020 16:49:11 -0700 Subject: [PATCH 09/29] Day 7 - Array Cardio 2 --- 07 - Array Cardio Day 2/index-START.html | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/07 - Array Cardio Day 2/index-START.html b/07 - Array Cardio Day 2/index-START.html index 969566ff78..9064971c92 100644 --- a/07 - Array Cardio Day 2/index-START.html +++ b/07 - Array Cardio Day 2/index-START.html @@ -26,15 +26,31 @@ // Some and Every Checks // Array.prototype.some() // is at least one person 19 or older? + const isAdult = people.some(person => { + const currentYear = (new Date()).getFullYear(); + return currentYear - person.year >= 19; + }); + console.log({isAdult}); + // Array.prototype.every() // is everyone 19 or older? + const allAdult = people.every(person => { + const currentYear = (new Date()).getFullYear(); + return currentYear - person.year >= 19; + }); + console.log({allAdult}); // 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(c => c.id === 823423); + console.log(comment.text); // Array.prototype.findIndex() // Find the comment with this ID // delete the comment with the ID of 823423 + const index = comments.findIndex(c => c.id === 823423); + comments.splice(index, 1); + console.table(comments); From da01a52f8a2694f735f2e19e8b2a02ada7351794 Mon Sep 17 00:00:00 2001 From: herron9 Date: Wed, 12 Aug 2020 16:18:45 -0700 Subject: [PATCH 10/29] Day 8 - Canvas --- 08 - Fun with HTML5 Canvas/index-START.html | 61 +++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/08 - Fun with HTML5 Canvas/index-START.html b/08 - Fun with HTML5 Canvas/index-START.html index 9da9b5b3c5..c6fd09a725 100644 --- a/08 - Fun with HTML5 Canvas/index-START.html +++ b/08 - Fun with HTML5 Canvas/index-START.html @@ -7,6 +7,67 @@ From 69c96f750f41ef43ea1c4aed1378520bb7efc0dc Mon Sep 17 00:00:00 2001 From: herron9 Date: Tue, 18 Aug 2020 16:37:08 -0700 Subject: [PATCH 20/29] day 17 - Sort without articles --- 17 - Sort Without Articles/index-START.html | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/17 - Sort Without Articles/index-START.html b/17 - Sort Without Articles/index-START.html index 2b6c9546e9..1e24c1e326 100644 --- a/17 - Sort Without Articles/index-START.html +++ b/17 - Sort Without Articles/index-START.html @@ -48,6 +48,16 @@ From 831e1def2f2b195c076b3584688999a8364871f5 Mon Sep 17 00:00:00 2001 From: herron9 Date: Wed, 19 Aug 2020 13:30:14 -0700 Subject: [PATCH 21/29] Day 18 - Adding up times --- .../index-START.html | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/18 - Adding Up Times with Reduce/index-START.html b/18 - Adding Up Times with Reduce/index-START.html index abdf4c91af..e384a56295 100644 --- a/18 - Adding Up Times with Reduce/index-START.html +++ b/18 - Adding Up Times with Reduce/index-START.html @@ -182,6 +182,51 @@ From d3474e91ba50165380d20ca69e6fc0d0613bf093 Mon Sep 17 00:00:00 2001 From: herron9 Date: Fri, 21 Aug 2020 12:29:44 -0700 Subject: [PATCH 22/29] Day 22 - Follow link highlighter --- .../index-START.html | 49 ++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/22 - Follow Along Link Highlighter/index-START.html b/22 - Follow Along Link Highlighter/index-START.html index 8476112b5e..ea211065c7 100644 --- a/22 - Follow Along Link Highlighter/index-START.html +++ b/22 - Follow Along Link Highlighter/index-START.html @@ -26,7 +26,54 @@ From fe96d7f0a43a9ea7bc036f2c999d0a4cf2d3bb2f Mon Sep 17 00:00:00 2001 From: herron9 Date: Fri, 21 Aug 2020 13:06:44 -0700 Subject: [PATCH 23/29] Day 24 - Sticky Nav --- 24 - Sticky Nav/README.md | 10 ++++++++++ 24 - Sticky Nav/index-START.html | 20 +++++++++++++++++++- 24 - Sticky Nav/style-START.css | 16 +++++++++++++++- 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 24 - Sticky Nav/README.md diff --git a/24 - Sticky Nav/README.md b/24 - Sticky Nav/README.md new file mode 100644 index 0000000000..0c849ed3f8 --- /dev/null +++ b/24 - Sticky Nav/README.md @@ -0,0 +1,10 @@ +# Knowledge + +## CSS Positioning +https://www.w3schools.com/css/css_positioning.asp + +>position: fixed; + +>An element with `position: fixed;` is positioned relative to the viewport, which means it always stays in the same place even if the page is scrolled. The top, right, bottom, and left properties are used to position the element. + +>A fixed element does not leave a gap in the page where it would normally have been located. \ No newline at end of file diff --git a/24 - Sticky Nav/index-START.html b/24 - Sticky Nav/index-START.html index e7bc67e9a5..bdc94c4e8d 100644 --- a/24 - Sticky Nav/index-START.html +++ b/24 - Sticky Nav/index-START.html @@ -53,7 +53,25 @@

A story about getting lost.

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Distinctio maiores adipisci quibusdam repudiandae dolor vero placeat esse sit! Quibusdam saepe aperiam explicabo placeat optio, consequuntur nihil voluptatibus expedita quia vero perferendis, deserunt et incidunt eveniet temporibus doloremque possimus facilis. Possimus labore, officia dolore! Eaque ratione saepe, alias harum laboriosam deserunt laudantium blanditiis eum explicabo placeat reiciendis labore iste sint. Consectetur expedita dignissimos, non quos distinctio, eos rerum facilis eligendi. Asperiores laudantium, rerum ratione consequatur, culpa consectetur possimus atque ab tempore illum non dolor nesciunt. Neque, rerum. A vel non incidunt, quod doloremque dignissimos necessitatibus aliquid laboriosam architecto at cupiditate commodi expedita in, quae blanditiis. Deserunt labore sequi, repellat laboriosam est, doloremque culpa reiciendis tempore excepturi. Enim nostrum fugit itaque vel corporis ullam sed tenetur ipsa qui rem quam error sint, libero. Laboriosam rem, ratione. Autem blanditiis laborum neque repudiandae quam, cumque, voluptate veritatis itaque, placeat veniam ad nisi. Expedita, laborum reprehenderit ratione soluta velit natus, odit mollitia. Corporis rerum minima fugiat in nostrum. Assumenda natus cupiditate hic quidem ex, quas, amet ipsum esse dolore facilis beatae maxime qui inventore, iste? Maiores dignissimos dolore culpa debitis voluptatem harum, excepturi enim reiciendis, tempora ab ipsam illum aspernatur quasi qui porro saepe iure sunt eligendi tenetur quaerat ducimus quas sequi omnis aperiam suscipit! Molestiae obcaecati officiis quo, ratione eveniet, provident pariatur. Veniam quasi expedita distinctio, itaque molestiae sequi, dolorum nisi repellendus quia facilis iusto dignissimos nam? Tenetur fugit quos autem nihil, perspiciatis expedita enim tempore, alias ab maiores quis necessitatibus distinctio molestias eum, quidem. Delectus impedit quidem laborum, fugit vel neque quo, ipsam, quasi aspernatur quas odio nihil? Veniam amet reiciendis blanditiis quis reprehenderit repudiandae neque, ab ducimus, odit excepturi voluptate saepe ipsam. Voluptatem eum error voluptas porro officiis, amet! Molestias, fugit, ut! Tempore non magnam, amet, facere ducimus accusantium eos veritatis neque.

- diff --git a/24 - Sticky Nav/style-START.css b/24 - Sticky Nav/style-START.css index b83b9c01ae..627e67c5d9 100644 --- a/24 - Sticky Nav/style-START.css +++ b/24 - Sticky Nav/style-START.css @@ -25,6 +25,10 @@ body { transition: transform 0.5s; } +.fixed-nav .site-warp { + transform: : scale(1); +} + header { text-align: center; height: 50vh; @@ -50,7 +54,13 @@ nav { z-index: 1; } -nav ul { +.fixed-nav nav { + /*note that a fixed element no longer t akes space, sort like float*/ + position: fixed; + box-shadow: 0 5px rgba(0,0,0,0.1); +} + +nav ul { margin: 0; padding:0; list-style: none; @@ -74,6 +84,10 @@ li.logo { font-size: 30px; } +.fixed-nav li.logo { + max-width: 500px; +} + li.logo a { color: black; } From 8a22cc267984f3598f5198a759904a0bf41c2d46 Mon Sep 17 00:00:00 2001 From: herron9 Date: Sat, 22 Aug 2020 15:34:10 -0700 Subject: [PATCH 24/29] Day 25 - Event Bubbling, Capture and Propagation --- .../README.MD | 9 +++++++++ .../index-START.html | 13 +++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 25 - Event Capture, Propagation, Bubbling and Once/README.MD diff --git a/25 - Event Capture, Propagation, Bubbling and Once/README.MD b/25 - Event Capture, Propagation, Bubbling and Once/README.MD new file mode 100644 index 0000000000..cbb90dd48c --- /dev/null +++ b/25 - Event Capture, Propagation, Bubbling and Once/README.MD @@ -0,0 +1,9 @@ +# Knowledge + +## Event Bubbling and capturing + +https://javascript.info/bubbling-and-capturing + +>There are two possible values of the `capture` option: +If it’s `false` (default), then the handler is set on the bubbling phase. +If it’s `true`, then the handler is set on the capturing phase. \ 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 7bd5931e01..11f73e6700 100644 --- a/25 - Event Capture, Propagation, Bubbling and Once/index-START.html +++ b/25 - Event Capture, Propagation, Bubbling and Once/index-START.html @@ -42,6 +42,19 @@ From 97ebd4b8acfc9332887b378469b4591a780d2448 Mon Sep 17 00:00:00 2001 From: herron9 Date: Sat, 22 Aug 2020 20:37:08 -0700 Subject: [PATCH 25/29] Day 26 - Stripe follow along nav --- 26 - Stripe Follow Along Nav/index-START.html | 53 ++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/26 - Stripe Follow Along Nav/index-START.html b/26 - Stripe Follow Along Nav/index-START.html index 608d0a6716..108c7b9f1c 100644 --- a/26 - Stripe Follow Along Nav/index-START.html +++ b/26 - Stripe Follow Along Nav/index-START.html @@ -124,7 +124,7 @@

Cool

} .cool > li { - position: relative; + position: relative; /*important!*/ display: flex; justify-content: center; } @@ -142,6 +142,17 @@

Cool

display: none; } + .trigger-enter { + display: block; + /*opacity: 1;*/ + } + + /* We will first change the display to block and wait 150ms before change opcaity*/ + /* This gives us a better transition*/ + .trigger-enter-active { + opacity: 1; + } + .trigger-enter .dropdown { display: block; } @@ -220,6 +231,46 @@

Cool

From 7cb0ecb676a6cd2c2074e60a9cddcb896fa873d4 Mon Sep 17 00:00:00 2001 From: herron9 Date: Sun, 23 Aug 2020 11:34:06 -0700 Subject: [PATCH 26/29] Day 27 - Click and Drag --- 27 - Click and Drag/index-START.html | 33 ++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/27 - Click and Drag/index-START.html b/27 - Click and Drag/index-START.html index b8609315f7..b273927875 100644 --- a/27 - Click and Drag/index-START.html +++ b/27 - Click and Drag/index-START.html @@ -35,6 +35,39 @@ From 6906c99a84289fccb90a2184d6b4dcb9940cdb9f Mon Sep 17 00:00:00 2001 From: herron9 Date: Sun, 23 Aug 2020 12:29:34 -0700 Subject: [PATCH 27/29] Day 28 - Video Speed controller --- 28 - Video Speed Controller/index-START.html | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/28 - Video Speed Controller/index-START.html b/28 - Video Speed Controller/index-START.html index 8bd536b18b..2f5dc1d78b 100644 --- a/28 - Video Speed Controller/index-START.html +++ b/28 - Video Speed Controller/index-START.html @@ -15,6 +15,24 @@ From 7f40a45c3f91b379a45290e11c08f60853cae7ef Mon Sep 17 00:00:00 2001 From: herron9 Date: Sun, 23 Aug 2020 16:35:03 -0700 Subject: [PATCH 28/29] Day 29 - Countdown Timer --- 29 - Countdown Timer/scripts-START.js | 113 ++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/29 - Countdown Timer/scripts-START.js b/29 - Countdown Timer/scripts-START.js index e69de29bb2..9989c8d4c8 100644 --- a/29 - Countdown Timer/scripts-START.js +++ b/29 - Countdown Timer/scripts-START.js @@ -0,0 +1,113 @@ +const displayLeft = document.querySelector('.display__time-left'); +const displayEnd = document.querySelector('.display__end-time'); + +const buttons = document.querySelectorAll('.timer__button'); +const customInput = document.querySelector('.custom'); + +// My shot + +let start = false; +let countDown; + +function startCountDown() { + start = true; + // let time = new Date(); + // time.setSeconds(time.getSeconds( + this.dateset.time)); + countDown = this.dataset.time; + display(); + // console.log(countDown); +} + +// buttons.forEach(button => button.addEventListener('click', startCountDown)); + +function display() { + if (!start) return; + + let secondsLeft = countDown; + const hours = Math.floor(secondsLeft / 3600); + secondsLeft = secondsLeft % 3600; + const minutes = Math.floor(secondsLeft / 60); + secondsLeft = (secondsLeft % 60); + + let text; + + if (hours > 0 ) { + text = hours + ':' + (minutes < 10 ? '0' + minutes : minutes) + + ':' + (secondsLeft < 10 ? '0' + secondsLeft : secondsLeft); + } else { + text = (minutes < 10 ? '0' + minutes : minutes) + + ':' + (secondsLeft < 10 ? '0' + secondsLeft : secondsLeft); + } + + displayLeft.textContent = text; + + countDown --; + + if (countDown === 0 ) { + displayLeft.textContent = ""; + start = false; + } + + console.log(hours, minutes, secondsLeft); +} + +// Not a good use here since interval might stop at some situation +setInterval(display, 1000); + + +// Wesbos's solution + +let countdown; + +function timer(seconds) { + // Clear any existing timer + 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); + }, 1000); +} + + +function displayTimeLeft(seconds) { + const minutes = Math.floor(seconds / 60); + const secondsLeft = (seconds % 60); + const display = `${minutes}:${secondsLeft < 10 ? '0' : ''}${secondsLeft}`; + + displayLeft.textContent = display; +} + +function displayEndTime(timestamp) { + const end = new Date(timestamp); + const hours = end.getHours(); + const minutes = end.getMinutes(); + displayEnd.textContent = `Be back at ${hours > 12 ? hours - 12 : hours}:${minutes}`; +} + +function startTimer() { + timer(parseInt(this.dataset.time)); +} + +function startCustomizedtimer(e) { + e.preventDefault(); + const mins = this.minutes.value; + timer(mins * 60); + + this.reset(); + +} + +buttons.forEach(button => button.addEventListener('click', startTimer)); +// Element with a name can be directly selected +document.customForm.addEventListener('submit', startCustomizedtimer); From f4987e693afa1d15ee45120b7130de5e3ba6b9b4 Mon Sep 17 00:00:00 2001 From: herron9 Date: Sun, 23 Aug 2020 17:28:30 -0700 Subject: [PATCH 29/29] Day 30 - Whack A Mole --- 30 - Whack A Mole/index-START.html | 48 ++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/30 - Whack A Mole/index-START.html b/30 - Whack A Mole/index-START.html index 2014ff458c..0699c4c719 100644 --- a/30 - Whack A Mole/index-START.html +++ b/30 - Whack A Mole/index-START.html @@ -36,7 +36,55 @@

Whack-a-mole! 0

const holes = document.querySelectorAll('.hole'); const scoreBoard = document.querySelector('.score'); const moles = document.querySelectorAll('.mole'); + let score; + let lastHole; + let timeUp = false; + + function randomTime(min, max) { + return Math.round(Math.random() * (max - min) + min); + } + + function randomHole(holes) { + const index = Math.floor(Math.random() * holes.length); + const hole = holes[index]; + if (hole === lastHole) { + return randomHole(holes); + } + + lastHole = hole; + return holes[index]; + } + + 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 bonk(e) { + if (!e.isTrusted) return; // Verify this is a real click not cheat + score ++; + + this.classList.remove('up'); + scoreBoard.textContent = score; + + } + + moles.forEach(mole => mole.addEventListener('click', bonk)); +