-
Notifications
You must be signed in to change notification settings - Fork 15
Intro to Frontend module #64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1863e72
Moved legacy js2w1 into foundation
adamblanchard ebb9106
Added fetch to learning goals in readme
adamblanchard ae99478
Updated lesson plan with Fetch code and exercises
adamblanchard 68cfd5f
Updated description mentioning promises being taught next week
adamblanchard 8130044
added fetch flipped classroom link in prep and lesson plan
adamblanchard 55056b3
Added fetch related optional homeworks
adamblanchard cfec115
Linting fixes
adamblanchard 325a6ab
Added stub for assignment projects for now
adamblanchard 1077ed9
updated main readme
adamblanchard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # Assignment Projects | ||
|
|
||
| TODO | ||
|
|
||
| We need to restructure/redesign the old javascript homework projects to fit with the new modules here. Leaving this stub for now, so we can point all old links here. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| # Introduction to Frontend | ||
| # Intro to Frontend | ||
|
|
||
| TODO | ||
| Here you can find module content and assignments for the Intro to Frontend module. | ||
|
|
||
| | Week | Topic | Preparation | Homework | Lesson plan | | ||
| | ---- | ----------------------------------------------------------------------------- | ------------------------------------- | ------------------------------------- | ------------------------------------- | | ||
| | 1. | [The browser environment, DOM, event listeners and making requests](./week1/) | [Preparation](./week1/preparation.md) | [Assignment](../assignment-projects/) | [Lesson plan](./week1/lesson-plan.md) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,171 @@ | ||
| # Intro to Frontend, Week 1 | ||
|
|
||
| ## Learning goals | ||
|
|
||
| Browser environment | ||
|
|
||
| - [ ] HTML vs CSS vs JS | ||
| - [ ] Client vs server | ||
| - [ ] Where is the script tag being loaded | ||
|
|
||
| DOM | ||
|
|
||
| - [ ] What is it and what do developers use the DOM for? | ||
| - [ ] DOM manipulation | ||
| - [ ] Get elements | ||
| - [ ] Insert elements | ||
| - [ ] Element manipulation (style, innerHTML, text) | ||
| - [ ] Window object | ||
| - [ ] Document object | ||
|
|
||
| Event listeners | ||
|
|
||
| - [ ] Document onload | ||
| - [ ] Click, submit, change, input - Focus on usage | ||
|
|
||
| Making requests | ||
|
|
||
| - [ ] Fetch (No promise explanation! Focus on usage) | ||
|
|
||
| ## Relevant links | ||
|
|
||
| - [Preparation](preparation.md) | ||
| - [Assignment](../../assignment-projects/) | ||
| - [Lesson plan](lesson-plan.md) | ||
|
|
||
| ## HTML interaction | ||
|
|
||
| Interacting with the HTML DOM is done through the document object in the browser. With the document object we can get html elements and change them. | ||
|
|
||
| For the next js part we use this html. | ||
|
|
||
| ```html | ||
| <html> | ||
| <body> | ||
| <h1>Javascript week 3</h1> | ||
| <div class="queue"></div> | ||
| <div id="test-id"></div> | ||
| <script src="js/review.js"></script> | ||
| </body> | ||
| </html> | ||
| ``` | ||
|
|
||
| ```js | ||
| // use the querySelector to select elements just like in css | ||
| const testIdElement = document.querySelector("#test-id"); | ||
| console.log(testIdElement); // logs the html element with id "test-id" | ||
|
|
||
| // Change the inner html of the test-id element | ||
| testIdElement.innerHTML = "test"; | ||
| // Change the background-color of the test-id element. Inline css changes is done via the style attribute on the element | ||
| testIdElement.style.backgroundColor = "blue"; | ||
|
|
||
| // It is also possible to create html elements | ||
| // Create a div element | ||
| const div = document.createElement("div"); | ||
| // Change its inner html | ||
| div.innerHTML = "We created this div!!!"; | ||
|
|
||
| // Lest append it to the div with the class queue | ||
| const queueDiv = document.querySelector(".queue"); | ||
| queueDiv.appendChild(div); | ||
| ``` | ||
|
|
||
| ## Code Commenting | ||
|
|
||
| First the straightforward part: how do we place comments in our code? | ||
|
|
||
| ### HTML | ||
|
|
||
| [W3Schools](https://www.w3schools.com/html/html_comments.asp) | ||
| Comments | ||
|
|
||
| ```html | ||
| <!-- Write | ||
| your comments here --> | ||
|
|
||
| <!-- Write your comments here --> | ||
| ``` | ||
|
|
||
| ### CSS | ||
|
|
||
| [MDN on CSS comments](https://developer.mozilla.org/en-US/docs/Web/CSS/Comments) | ||
|
|
||
| ```css | ||
| /* Comment */ | ||
|
|
||
| /* | ||
| A comment | ||
| which stretches | ||
| over several | ||
| lines | ||
| */ | ||
| ``` | ||
|
|
||
| ### JavaScript | ||
|
|
||
| Single line comments | ||
|
|
||
| ```js | ||
| // Change heading: | ||
| document.getElementById("myH").innerHTML = "My First Page"; | ||
| ``` | ||
|
|
||
| Single line comments at end of the line: | ||
|
|
||
| ```js | ||
| const x = 5; // Declare x, give it the value of 5 | ||
| ``` | ||
|
|
||
| Writing js documentation: [JSDoc](https://usejsdoc.org/) <!-- http-trash --> | ||
|
|
||
| ### When to comment? | ||
|
|
||
| Now for the hard part: when to comment? When you work for different companies, you will see different styles. Embrace something you like, and then learn to let go. Google on "when to comment code?" and you'll find a big bunch of different opinions. | ||
|
|
||
| The general concept is, however, that it is there to help make the code more easy to understand. Note, however, that comments can also make code more difficult to understand when not applied properly. | ||
|
|
||
| ## Events | ||
|
|
||
| Events in JavaScript are things like: | ||
| A timer has just finished, a user clicked a button, our page has loaded, | ||
| someone types into an input element or we have just gotten some data from a server. | ||
| When these events happen, we usually want to add some functionality. | ||
| For example, when a user clicks the like button (event), we want to increment the like counter and color the like button blue. | ||
| Or when someone clicks "Close cookies" (event) we want to remove the cookie div. | ||
|
|
||
| Lets first try to create some js that waits for 2 seconds and the console.logs out "2 seconds has elapsed!" | ||
|
|
||
| In JavaScript we use an _event listener_ to listen: | ||
|
|
||
| ```javascript | ||
| setTimeout(function () { | ||
| console.log("2 seconds has elapsed!"); | ||
| }, 2000); | ||
|
|
||
| // Cool, now lets make a function as a variable: | ||
| const fourSecondLog = function () { | ||
| console.log("4 seconds has elapsed!"); | ||
| }; | ||
|
|
||
| setTimeout(fourSecondLog, 4000); | ||
| ``` | ||
|
|
||
| Now lets try and log out "button clicked!" when a button is clicked. | ||
|
|
||
| To check if a button gets clicked we use a what is called an _event listener_. | ||
|
|
||
| Imagine a person listening to the click of a button and every time he hears a click he yells out "CLICKED". | ||
|
|
||
| ```javascript | ||
| const buttonElement = document.querySelector("button"); | ||
| buttonElement.addEventListener("click", function () { | ||
| console.log("Button clicked!"); | ||
| }); | ||
|
|
||
| const buttonClicked = function () { | ||
| console.log("Button clicked as a variable!"); | ||
| }; | ||
| // Cool man! Lets try and add that function as a variable. | ||
| buttonElement.addEventListener("click", buttonClicked); | ||
| ``` | ||
42 changes: 42 additions & 0 deletions
42
courses/Foundation/intro-to-frontend/week1/assets/carGenerator.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /** | ||
| * Get random integer between two numbers, found here: https://stackoverflow.com/a/7228322 | ||
| * @param {integer} min - The min number | ||
| * @param {integer} max - The max number | ||
| * @returns {Number} Random number between min and max | ||
| */ | ||
| function randomIntFromInterval(min, max) { | ||
| return Math.floor(Math.random() * (max - min + 1) + min); | ||
| } | ||
|
|
||
| /** | ||
| * Get an array with car objects with random color and speed | ||
| * @param {integer} numberOfCars - The number of cars | ||
| * @returns {array} Array containing the car objects | ||
| */ | ||
| function generateCars(numberOfCars) { | ||
| const cars = []; | ||
|
|
||
| const carMakes = ["Honda", "BMW", "Fiat", "Skoda", "Volvo"]; | ||
| const carColors = [ | ||
| "lightgrey", | ||
| "lightcyan", | ||
| "lightyellow", | ||
| "lightgreen", | ||
| "lightcoral", | ||
| "lightpink", | ||
| ]; | ||
|
|
||
| for (let i = 0; i < numberOfCars; i++) { | ||
| const car = {}; | ||
| const randomMakeIndex = randomIntFromInterval(0, carMakes.length - 1); | ||
| const randomColorIndex = randomIntFromInterval(0, carColors.length - 1); | ||
|
|
||
| car.make = carMakes[randomMakeIndex]; | ||
| car.color = carColors[randomColorIndex]; | ||
| car.speed = randomIntFromInterval(0, 100); | ||
|
|
||
| cars.push(car); | ||
| } | ||
|
|
||
| return cars; | ||
| } |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't find any relevant content for Fetch to copy into here (which covers the other topics)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't added anything here since we didn't have anything in the legacy modules. But i really think after this restructure, a valuable task would be to go through each module and tidy up content like this.