diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 000000000..d06ffd2ea Binary files /dev/null and b/.DS_Store differ diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..723ef36f4 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea \ No newline at end of file diff --git a/README.md b/README.md index ee8d737c0..5e3f75cff 100644 --- a/README.md +++ b/README.md @@ -1,67 +1,128 @@ -# JavaScript -Brainstorm JavaScript module +# DEPRECATED - JavaScript 1 +This module has been replace with the JavaScript module, find it [here](https://github.com/HackYourFuture/JavaScript) -Here is an overview of the brainstorm sessions for the JavaScript modules. -Feel free to make suggestions or add anything. -If everyone can help out with elaborating on the different subjects that would be great! -What you see below is a rough layout for the first three Javascript modules. Feel free to deviate from this layout but try to cover all of the subject matters listed. +``` +In this module you'll make a start into wonderful world of programming. We will be using the programming language `JavaScript` to do so. You'll learn about the basic building blocks of programming: `loops`, `functions`, `control flow` and more. Consider these as the ABC's of programming, without them it's impossible to write working software! +You'll be learning two main things: -# What - -## Module 1 (3 weeks) - * what is a CLI - * Basic Git commands by CLI - * publish your websites on Git (UI) - * branch and push, clone - * Intro Javascript (What is it, where can you use it for) - * Querying the DOM - * Basic datatypes (array, string, number, bool) - * Loops, if statements - * Browser debugging & ClI debugging +1. **Fundamental concepts in programming**. While we're using JavaScript to illustrate these concepts, it's important to keep in mind that what you will learn is applicable to **any** programming language. They might differ in syntax (a fancy term for the arrangement of words in a language in order for it to make sense), but the functionality will be the same: a loop will always be a loop. +This should be your mindset when you're learning concepts: **I'm learning how to become a software developer that can adjust to any language used, because I know what the underlying principles and concepts are**. -## Module 2 (3 weeks) - * Code conventions - * Function declaration and excecution (code flow) - * Scope - * Github documentation (readme, description, open sourcery) - * Git tracking, terminology - * Advanced datatypes(objects) - * Code flow - * JavaScript functions, callbacks (events) - * Writing a multi function program (or game :) +2. **How to think like a programmer**. In one sentence this means: knowing how to solve problems using a computer. Let's split that up in two parts: `how to solve problems` refers to the ability to identify issues and find effective solutions. `computationally` refers to the ability to think in logical steps that the computer can understand and execute. -## Module 3 (3 weeks) - * HTTP requests - * APIs! - * JSON - * Polling external data dynamically - * (Unit testing) +This should be your mindset when you're learning how to think : **I'm learning how to think in logical steps, identifying cause and effect, and always looking for solutions**. -## Optional: - * Code patterns - * Observer patterns - * Watcher patterns +## Before you start! +### 1. Install some new software! -# How +In order to test your JavaScript code, you'll be using software that will execute your files from the command line. This software is called [Node.js](https://nodejs.org/en/download/). Download the Long-Term Support (LTS) version for your specific operating system. - * Try to find an example you can expand on. For instance coding a website that lists the students in the class along with their Github Repos. This way you can show anything from DOM querying to objects (for each student) and even load up the Github API - * Live coding in class to show how certain features work. - * Ask students to present their work, let them know failing while coding isn't just accepted it's encouraged. Fail often and fail early. - * Homework is listed on Trello and handed in on Github - * There's no strict lesson plan, adapt to students' need and level. Try to make up more advanced challenges for quick learners. - * Test after every module, if students fail they can't move on to the rest of the program. It is possible to redo a module (one time). +- For Windows, click [here](https://nodejs.org/dist/v12.16.1/node-v12.16.1-x86.msi) +- For Mac, click [here](https://nodejs.org/dist/v12.16.1/node-v12.16.1.pkg) +- For Linux, click [here](https://nodejs.org/dist/v12.16.1/node-v12.16.1-linux-x64.tar.xz) +After you've installed it, go to your command line interface. Type in the following command: -## Extra extra - * Slackbot - * Work in one environment +``` +node --version +``` +It should show you version `v12.16.1` or higher. -## After - * Feedback from students and teachers on the modules +### 2. A new way of submitting homework! +Starting from this module you'll submit homework in a different way. You will be only using GIT and GitHub and work **like a real developer would**: pushing code from your computer to GitHub and making pull requests! +Before you start with the homework, make a `fork` of the following repository: [HackYourHomework/JavaScript1](https://www.github.com/hackyourhomework/javascript1). You'll always use the **HackYourHomework** version of the module repository whenever you have to submit your homework. +Here are the steps to get started: + +1. `fork` the HackYourHomework repository to your personal account. +2. `clone` your forked repository to your computer. +3. Make `GIT` branches for each week. Start at the `master` branch and execute the following (note that they're 3 different commands): + +`console +foo@bar:~$ git branch week1-YOURNAME +foo@bar:~$ git branch week2-YOURNAME +foo@bar:~$ git branch week3-YOURNAME +` + +4. `checkout` to `week1-YOURNAME` +5. Get started with making your homework! + +Here's a video in order that shows you how it's done: [How to Submit Your Homework](https://www.youtube.com/watch?v=CpYARPYGQU8) + +### 3. Presentation module +Besides learing a lot of technical concepts you'll be focussing on the softskills as well. Please have a look at [this](https://github.com/HackYourFuture/presentation-module) RePo for more details. + +## Learning goals + +In order to successfully complete this module you will need to master the following: + +- Have an idea of what `computer programming` is +- Know the basic building blocks of `JavaScript` +- Correctly write and use `variables`, `functions` and `loops` +- Understand the `control flow` + +## How to use this repository + +### Repository content + +This repository consists of 3 essential parts: + +1. `README`: this document contains all the required theory you need to understand **while** working on the homework. It contains not only the right resources to learn about the concepts, but also lectures done by HackYourFuture teachers. This is the **first thing** you should start with every week +2. `MAKEME`: this document contains the instructions for each week's homework. Start with the exercises rather quickly, so that you can ground the concepts you read about earlier. +3. `LESSONPLAN`: this document is meant for teachers as a reference. However, as a student don't be shy to take a look at it as well! + +### How to study + +Let's say you are just starting out with the JavaScript1 module. This is what you do... + +1. The week always starts on **Wednesday**. First thing you'll do is open the `README.md` for that week. For the first week of `JavaScript1`, that would be [Week1 Reading](/Week1/README.md) +2. You spend **Wednesday** and **Thursday** going over the resources and try to get a basic understanding of the concepts. In the meanwhile, you'll also implement any feedback you got on last week's homework (from the HTML-CSS module) +3. On **Friday** you start with the homework, found in the `MAKEME.md`. For the first week of `JavaScript1`, that would be [Week1 Homework](/Week1/MAKEME.md) +4. You spend **Friday** and **Saturday** playing around with the exercises and write down any questions you might have +5. **DEADLINE 1**: You'll submit any questions you might have before **Saturday 23.59**, in the class channel +6. On **Sunday** you'll attend class. It'll be of the Q&A format, meaning that there will be no new material. Instead your questions shall be discussed and you can learn from others +7. You spend **Monday** and **Tuesday** finalizing your homework +8. **DEADLINE 2**: You submit your homework to the right channels (GitHub) before **Tuesday 23.59**. If you can't make it on time, please communicate it with your mentor +9. Start the new week by going back to point 1! + +In summary: + +![Weekflow](assets/weekflow.png) + +To have a more detailed overview of the guidelines, please read [this document](https://docs.google.com/document/d/1JUaEbxMQTyljAPFsWIbbLwwvvIXZ0VCHmCCN8RaeVIc/edit?usp=sharing) or ask your mentor/class on Slack! + +### Video lectures + +For each module HackYourFuture provides you with video lectures. These are made by experienced software developers who know what they're talking about. The main teacher for this module will be [Uday Khaki](https://hackyourfuture.slack.com/team/U3T5HDP0W): former HackYourFuture student and now successful web developer for several years! + +You can find out more about him here: + +- [@Uday on Slack](https://hackyourfuture.slack.com/team/U3T5HDP0W) + +Learn from Uday in the following playlist of videos he has made for you! (Click on the image to open the link) + +HYF Video + +## Planning + +| Week | Topic | Reading Materials | Homework | Lesson Plan |Presentation module | +| ---- | --------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |-----------| +| 1. | What is JavaScript?, Variables, Data Structures & Naming Conventions | [Reading W1](https://github.com/HackYourFuture/JavaScript1/tree/master/Week1/README.md) | [Homework W1](https://github.com/HackYourFuture/JavaScript1/tree/master/Week1/MAKEME.md) | [Lesson Plan W1](https://github.com/HackYourFuture/JavaScript1/tree/master/Week1/LESSONPLAN.md) |[W1 presentations](https://github.com/HackYourFuture/presentation-module/blob/main/week1.md) | +| 2. | Statements vs. Expressions, Control flow, Loops, Operators, Conditional statement | [Reading W2](https://github.com/HackYourFuture/JavaScript1/tree/master/Week2/README.md) | [Homework W2](https://github.com/HackYourFuture/JavaScript1/tree/master/Week2/MAKEME.md) | [Lesson Plan W2](https://github.com/HackYourFuture/JavaScript1/tree/master/Week2/LESSONPLAN.md) |[W2 presentation](https://github.com/HackYourFuture/presentation-module/blob/main/week2.md) | +| 3. | Functions, Thinking like a programmer I, How JavaScript relates to HTML/CSS | [Reading W3](https://github.com/HackYourFuture/JavaScript1/tree/master/Week3/README.md) | [Homework W3](https://github.com/HackYourFuture/JavaScript1/tree/master/Week3/MAKEME.md) | [Lesson Plan W3](https://github.com/HackYourFuture/JavaScript1/tree/master/Week3/LESSONPLAN.md) | + +## Finished? + +Did you finish the module? Good job! You're doing great! + +If you feel ready for the next challenge, click [here](https://www.github.com/HackYourFuture/JavaScript2) to go to JavaScript2! + +_The HackYourFuture curriculum is subject to CC BY copyright. This means you can freely use our materials, but just make sure to give us credit for it :)_ + +Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.``` diff --git a/Week1/.DS_Store b/Week1/.DS_Store new file mode 100644 index 000000000..0e98056ea Binary files /dev/null and b/Week1/.DS_Store differ diff --git a/Week1/LESSONPLAN.md b/Week1/LESSONPLAN.md new file mode 100644 index 000000000..66ffd2359 --- /dev/null +++ b/Week1/LESSONPLAN.md @@ -0,0 +1,276 @@ +# Lesson Plan JavaScript1 Week 1 + +## Agenda + +The purpose of this class is to introduce to the student: + +- The 2 types of websites: static vs. dynamic +- The pillars of web development: HTML/CSS/JavaScript + - where JavaScript can run: Browser / Node +- What are variables +- How to name variables properly +- What are the basic data types +- What are the compound data types + +## Core concepts + +_FIRST HALF (12.00 - 13.30)_ + +## 1. The 2 types of websites: static vs. dynamic + +### Explanation + +Static websites usually come with a fixed number of pages that have a specific layout. When the page runs on a browser, the content is literally static and doesn’t change in response to user actions. A static website is usually created with HTML and CSS +Compared to static websites, which are purely informational, a dynamic website is more functional. It allows users to interact with the information that is listed on the page. Of course, that requires utilizing more than just HTML code. + +### Example + +Examples the two different kind of websites + +- Static: https://www.atlassian.com/time-wasting-at-work-infographic +- Dynamic: https://www.facebook.com/ + +### Exercise + +Discuss in class which claim belongs to which type of website: + +- Content of Web pages can not be change at runtime. +- Server side languages such as PHP, Node.js are used. +- Content of Web pages can be changed. +- No interaction with database possible. +- Interaction with database is possible +- It is faster to load as compared to the other typ of website. +- It is slower then static website. +- Lower Development costs. +- Content may change every time the page is loaded. +- Feature of Content Management System. +- HTML, CSS, Javascript is used for developing the website. +- Same content is delivered every time the page is loaded. + +### Essence + +[In the link is an article with (dis)advantages of both static and dynamic websites.](https://www.spiderwriting.co.uk/static-dynamic.php) + + Static: + Advantage: + - Flexible + - Cheaper + Disadvantages: + - not updating content + - Scalability + + Dynamic: + Advantage: + - Easy to pull in data on stuctured and organised way + - Content management system + Disadvantage: + - Design is more fixed, because the pages are more of a template + - Costs + +## 2. The pillars of web development: HTML/CSS/JavaScript + +### Explanation + +- HTML defines what the content is. +- CSS defines the appearance of the page. +- JavaScript defines behavior of the page. +- Where can JavaScript run: + - browser + - Node + +### Example + +- An example about relationship between HTML, CSS and Javascript using a metaphor of building a city: https://blog.codeanalogies.com/2018/05/09/the-relationship-between-html-css-and-javascript-explained/ + +### Exercise + +Let students fork and then clone the repository. +Let students create a classwork directory and create an index.html along with an app.js. Script tag should be added to the end of body tag(reason for doing so is part of JS2 Week1). + +The end result should look like: + +``` +- js1-week1-classwork + - index.html + - app.js +``` + +### Essence + +Up until now at HackYourFuture, we have been writing websites using HTML and CSS. Even though a website written with these two languages works just fine, it is only a static page. + +These static pages can interact with a visitor only through the use of forms. Once a form is filled out and submitted, a request is sent back to the server where a new static web page is constructed and eventually downloaded into the browser. + +A big disadvantage of web pages like this is that the only way that a visitor has of interacting with the page is by filling out the form and waiting for a new page to load. + +It doesn't exhibit any dynamic behavior like: + +1. reacting to user actions such as mouse click events or key presses. +2. rendering complex animations +3. sending requests over network to servers and fetching a response +4. and this is where JavaScript steps in. + +## 3. What are variables (const & let) & naming conventions + +### Explanation + +In JavaScript, there are three ways of creating variables. + +- var +- let +- const + +While `var` has been used in JavaScript for a long period of time, `let` and `const` are recent additions having been introduced in ES6. + +Three different stages of working with variables are: + +- Variable Declaration + - Declaration means creating a variable and providing it with a name. During the whole program, a variable can be declared only once. +- Variable Initialization + - Initialization is declaring a variable and assigning it an initial value at the time of declaration. By default, all variables created in JavaScript have undefined as the default value unless explicitly given a different value. +- Variable (Re)Assignment + - Variable assignment means throwing away the old value of a variable and replacing it with a new one. Initialization can be thought of as a special way of assignment. + +https://github.com/HackYourFuture/fundamentals/blob/master/fundamentals/variables.md + +### Example + +```javascript +// Variable Declaration +var firstName; +let lastName; +const age; // is this correct??? + +console.log(firstName); +console.log(lastName); +console.log(age); +``` + +```javascript +// Variable Initialization + +var firstName = "Yash"; +let lastName = "Kapila"; + +const age = 29; + +console.log(firstName); +console.log(lastName); +console.log(age); +``` + +```javascript +var firstName = "Tom"; +let lastName = "Hanks"; + +console.log(firstName); +console.log(lastName); + +// Assigning variables to a different value +firstName = "Hanks"; +lastName = "Tom"; + +console.log(firstName); +console.log(lastName); +``` + +### Exercise + +1. Create 2 variables using the `let` keyword + + - make 1 variable contain your first name + - the second variable should have no value assigned + +1. Make 2 variables using the `const` keyword + - the first variable should contain the city you currently stay at + - come up with name and a value for the second variable yourself + + +### Essence + +Any application written in any programming language requires data or information to work with. This information can be as simple as a string, number or complex types like a list of strings, a mix of strings and numbers etc. + +For example, your name and age are simple pieces of information, a string and a number respectively. On the other hand, your house address could be considered as a complex set of information including house number, street name, city, postcode and country. + +Variables are simply named storage/pointer for this information. + +_SECOND HALF (14.00 - 16.00)_ + +## 4. The basic data types (string, boolean, number, undefined, null) + +### Explanation + +In JavaScript, a primitive (primitive value, primitive data type) is data that is not an object and has no methods. There are 7 primitive data types: `string`, `number`, `bigint`, `boolean`, `null`, `undefined`, and `symbol`. + +Boolean — true or false +Null — no value +Undefined — a declared variable but hasn’t been given a value +Number — integers, floats, etc +String — an array of characters i.e words +Symbol — a unique value that's not equal to any other value (not used during HYF) + +### Example + +- `string`, e.g. "HackYourFuture" +- `number`, e.g. 5, or 10.6 +- `boolean`, e.g. `true` or `false` +- `array`, e.g. `[1, 2, 3]` or `['what', 'is', 'your', 'name']` +- `null` \* +- `undefined` \* +- `symbol` e.g. `new Symbol('example')` + +\* The values `null` and `undefined` are very similar in JavaScript, but they behave a bit differently. The difference is that `null` always has type "object", and `undefined` always has type "undefined". +Whenever you declare a variable (using `let`), but you don't set a value, the variable will become `undefined`. JavaScript will never make a variable `null` unless you explicitly program it. + +### Exercise + + +Everybody has four minutes to find a way to store all basic data types in a variable by making use of the typeof operator: + +```js +let x = 5; +let typeOfX = typeof x; // -> "number" +``` + +### Essence + +In this way we can store a lot of data in a compact way, while the computer/compiler knows how to interpret the 1's and 0's/ + +## 5. The compound data types (object, array) + +### Explanation + +Pieces of information often form a group. For example the names of all the students in this class can be grouped together +as a list. In JavaScript lists are stored in a datatype called an `Array`. + +Another way pieces of information can form a group are multiple properties of the same thing. For example the dimensions +of this room: length, width, height. These groups of information are stored in a datatype called an `Object`. + +### Example + +- `array`\*, e.g. `[1, 2, 3]` or `['Gijs', 'Jim', 'Noer', 'Wouter']` +- `object`, e.g. `{name: 'Wilgert', shoeSize: 42}`, or the special object `null` + +### Exercise + +1. Create a list of your favorite types of food/dishes like this: + +```js +const foods = ['Chocolate', 'Risotto', 'Tuna melt']; +``` + +2. Create an object that contains the properties of your town/city like this: + +```js +const city = { + name: 'Huizen', + province: 'Noord-Holland', + population: 50000, + capital: false, +}; +``` + +### Essence + +- Object key: value +- Array numeric index: value diff --git a/Week1/MAKEME.md b/Week1/MAKEME.md new file mode 100644 index 000000000..9b5330f0f --- /dev/null +++ b/Week1/MAKEME.md @@ -0,0 +1,205 @@ +# Homework JavaScript1 Week 1 + +## **Todo list** + +1. Practice the concepts +2. JavaScript exercises +3. Code along + +## **1. Practice the concepts** + +Before we learn how to build actual applications, we first need to gain experience using JavaScript in a computational way. This teaches us how to think like a programmer, and gives us more experience with the language itself. + +In the following exercises you'll learn how to use different JavaScript concepts to solve common computational problems: + +- [Learn-js](https://www.learn-js.org/). Do all the `Learn the basics` exercises. +- [Codecademy: Introduction to JavaScript](https://www.codecademy.com/learn/introduction-to-javascript/modules/learn-javascript-introduction). Do all the exercises (#1 to #10). +- [FreeCodeCamp: Introduction to JavaScript](https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript). Do at least 20 exercises, you can choose whichever ones you feel are challenging enough. + +## **2. JavaScript exercises** + +> Inside of your `JavaScript1` fork and inside of the `Week1` folder, create a folder called `homework`. Inside of that folder, create a folder called `js-exercises`. For all the following exercises create a new `.js` file in that folder (10 files in total). Make sure the name of each file reflects its content: for example, the filename for exercise one could be `logHello.js`. + +> In each file, start off with the string `'use strict'`. This will make sure the code interpreter will enforce stronger rules when looking at your code. + +> Before starting, make sure you have [Node.js](https://nodejs.org/en/download/) installed on your computer. You'll use this to execute your code to check if it works. + +**Exercise 1: Hello world!** + +Write a statement, using the `console.log()` function. It should fulfill the following requirements: + +- It takes a string as an argument +- The string should contain the message `"Hello world!"` +- Execute the function 10 times, each time using the phrase in different languages + +For example: + +``` +Halo, dunia! // Indonesian +Ciao, mondo! // Italian +Hola, mundo! // Spanish +``` + +Finished? Using the command line, navigate to your `js-exercises` folder and type in the following to test your code: + +```console +foo@bar:~$ node FILENAME.js +``` + +Expected output: It should show the message `Hello world!` in 10 different languages. + +**Exercise 2: Error debugging** + +Consider the following code: + +```js +console.log('I'm awesome'!; +``` + +Here are the requirements: + +- Copy the code in your `.js` file and run it in the command line using `node`. + +You will see that you will get a [SyntaxError](https://techterms.com/definition/syntax_error). + +- **Correct the mistake**. + +> Hint: the SyntaxError message will give you some indication of what the error _might_ be, but figure out yourself how to correct it! + +Expected output: When done right, the command line should show the message `I'm awesome!`. + +**Exercise 3: Log the number** + +Follow the steps. Make sure that each step is written on the line after. + +1. First, declare your variable `numberX`. Do not _initialize_ it (which means, don't give it a starting value) yet +2. Add a `console.log` statement that explains in words _what you think_ the value of `x` is +3. Add a `console.log` statement that logs the value of `numberX`. +4. Now _initialize_ your variable `numberX` with a number (also called an `integer` in computer science terms) +5. Next, add a `console.log` statement that explains _what you think_ the value of `numberX` is +6. Add a `console.log` statement that logs the value of `numberX` + +**Exercise 4: Log the string** + +Follow the steps. Make sure that each step is written on the line after. + +1. Declare a variable `myString` and assign a string to it. Use your full name, including spaces, as the content for the string. +2. Write a `console.log` statement in which you explain in words _what you think_ the value of the string is. +3. Now `console.log` the variable `myString`. +4. Now reassign to the variable `myString` a new string. +5. Just like what you did before write a `console.log` statement that explains in words _what you think_ will be logged to the console. +6. Now console.log `myString` again. + +**Exercise 5: Round a number and log it** + +Follow the steps. Make sure that each step is written on the line after. + +1. Declare a variable `z` and assign the number `7.25` to it. +2. Write a `console.log` statement in which you log the value of `z`. +3. Declare another variable `a` that has the value of `z` but rounded to the nearest integer. +4. Write a `console.log` statement in which you log the value of `a`. +5. So now we have `z` and `a` find a way to compare the two values and store the highest of the two in a new variable. +6. Write a `console.log` statement in which you log the value of the highest value. + +**Exercise 6: Log an array of animals** + +Follow the steps. Make sure that each step is written on the line after. + +1. Declare variable and assign to it an empty array. Make sure that the name of the variable indicates it contains more than 1 item. For example `items` instead of `item`. +2. Write a `console.log` statement that explains in words _what you think_ the value of the array is. +3. Write a `console.log` statement that logs the array. +4. Create a new variable with an array that has 3 of your favorite animals, each in a different string. Make sure the name of the variables says something about what the variable contains. +5. Write a `console.log` statement that logs the second array. +6. Add a statement that adds another string ("Piglet)" to the array of animals. +7. Write a `console.log` statement that logs the second array! + +**Exercise 7: Log the length of a string** + +Follow the steps. Make sure that each step is written on the line after. + +1. Declare a variable called `mySentence` and initialize it with the following string: "Programming is so interesting!". +2. Figure out (using Google) how to get the length of `mySentence`. +3. Write a `console.log` statement to log the length of `mySentence`. + +**Exercise 8: Type checker** + +Create a `function` that fulfills the following requirements: + +- Takes in 2 arguments +- Check the data type of each +- Compares each data type +- Logs to the console the message `SAME TYPE` if they are the same type. If they are different types log `Not the same...`. + +Follow the steps: + +1. Declare 4 variables: 2 must be `strings` and 2 must be `objects` +2. Create 6 conditional statements, where for each you check if the data type of one variable is the same as the other +3. Find out how to check the type of a variable +4. Write 2 `console.log` statements to log the type of 2 variables, each with a different data type +5. Now compare the types of your different variables with one another +6. Log `Not the same...` when the types are different + +Here's an incomplete example of how it could look: + +```js +// Declare all variables +let x = 9; +let y = 67; + +// Check data type +console.log(...); + +// Check if data type is the same +if (...) { + console.log('SAME TYPE'); +} +``` + +**Exercise 9: Log the remainder** + +Answer the following questions. For each, write in comments what the answer is followed by how you came to that conclusion: + +1. If `x` equals 7, and the only other statement is `x = x % 3`, what would be the value of `x` after the calculation? +2. If `y` equals 21, and the only other statement is `y = y % 4`, what would be the value of `y` after the calculation? +3. If `z` equals 13, and the only other statement is `z = z % 2`, what would be the value of `z` after the calculation? + +**Exercise 10: Compare arrays** + +Follow the steps: + +1. Declare 2 variables, that each hold an array. The first array should have 4 items, the second 7 items +2. Find out how to get the length of each array. Write a `console.log` statement that shows the length of each array + +```js +const array = ["hello", 123, true, { name: "Noer" }]; + +console.log('The length of the array is...' + ...); +``` + +3. Write a conditional statement that checks if both are of equal length. If they are, log to the console `They are the same!`, if not log `Two different sizes` + +## **3. Code along** + +> Create a new GitHub repository for this project. It's a portfolio piece! + +We don't want to lose the connection with HTML/CSS, so in the following tutorial you'll learn how to build a simple web application use HTML/CSS and JavaScript. + +You'll first write the HTML and CSS, to provide structure and style to the page. When doing so, notice how the developer chooses to do this. Why do they use this tag instead of something else? Why do they give an element a certain class name? + +After, the developer will write JavaScript code. You'll notice it's different from how you've used JavaScript. It is something we call **DOM Manipulation**. Don't worry, you don't need to master this just yet. Just follow along and do some research yourself if you already want to learn more about it! + +- [Calculator](https://www.youtube.com/watch?v=6v4vBXL-qkY) + +## **SUBMIT YOUR HOMEWORK!** + +After you've finished your todo list it's time to show us what you got! Starting from this week you'll be submitting all your homework through GitHub. What you'll be doing is upload all your files to a separate repository. + +Go over to [HackYourHomework/JavaScript1](https://www.github.com/HackYourHomework/JavaScript1). Notice how it's **HackYourHomework**, a repository meant to submit the homework! + +Then take a look at the following [guide](../hand-in-homework-guide.md) to see to set everything up. + +The homework that needs to be submitted is the following: + +1. JavaScript exercises + +_Deadline Saturday 23.59 CET_ diff --git a/Week1/README.md b/Week1/README.md index d896b8432..bbcac17ac 100644 --- a/Week1/README.md +++ b/Week1/README.md @@ -1,13 +1,199 @@ -# Lecture one - -# Covered in class: - -## Git introduction - * publish your websites on Git (UI) - * branch and push, clone - -## Homework - * Create a .js file that prints something to the console and add it to your github pages repository. - * Recreate your CV (from the HTML/CSS module) on pages.github.io using this tutorial https://pages.github.com/ and share your link on Trello - * Complete the first couple assignments on Codecademy (up until Math operators I) - * Use document.querySelector to select an element in your github pages website and change the innerHTML. +# Reading Material JavaScript1 Week 1 + +## Agenda + +These are the topics for week 1: + +1. What is programming? + - Software + - What is a programming language? +2. What is web development? + - Web development vs. software development + - Web development vs. web design + - Website vs. web application +3. What is JavaScript? +4. What are variables? + - The keywords: let, const, var + - values +5. What are data types? + - 6 basic types + +## 0. Video Lectures + +Your teacher Uday has made video lectures for this week's material. You can find them here: [Videos 1 - 10](https://www.youtube.com/playlist?list=PLVYDhqbgYpYUiqH8IxLJ5qomkEGMzes1q) + +HYF Video + +## 1. What is programming? + +Programming is giving a computer instructions written in a language it can understand, in order to solve a problem you (or the company you work for) have. We don't necessarily need computers to solve problems, but we use them because they provide several benefits: + +1. They are fast +2. Cheap to use +3. Can work 24/7 (as long as it has power) + +This is important to note: a computer is a `tool` we use to make our lives easier. + +- [What is a Computer?](https://www.youtube.com/watch?v=rRSD128KWIM) +- [What Do Computers Do?](https://www.youtube.com/watch?v=92TaQRBwPSs) + +In order to use this tool, we need to talk to it in a way it understands (programming language) and give it commands on what to do (the act of programming). However, despite the power a computer has it is not very smart. It can't do anything without being told **exactly** what it needs to do to solve a problem, step-by-step. This is why we learn how to program: in order to tell the computer to do what we want it to do. + +Go through the following resources to learn more about what programming is: + +- [What is programming?](https://www.youtube.com/watch?v=3tWMQ3ZMjbg) +- [What do programmers do?](https://www.youtube.com/watch?v=kEjCfsrotAM) +- [Introduction into programming Playlist](https://www.youtube.com/playlist?list=PLRqwX-V7Uu6ZYJC7L-r6rX6utt6wwJCyi) + +### Software + +As a software developer (synonym to 'programmer' or 'software engineer'), you will write these instructions in order to create 'software'. Look at the following video to get a better idea of what software is: + +- [What is software?](https://www.youtube.com/watch?v=MSA3WsGeTNI) + +### What is a programming language? + +Programming is done using a programming language. Why do we need a language to communicate with the computer? At its most basic level, a computer operates based on 0's and 1's: the 0 means 'off', and the 1 means 'on' (think of it like a light switch that either turns the light on or off). + +Smart people decided to make working with this easier to understand, so that a lot of people can more simply communicate with a computer. This is how the development of programming languages started: by defining a vocabulary, grammar and syntax to put more organization to the 0's and 1's, we can more simply communicate exactly what we want to computer to do. + +- [What is a programming language?](https://www.youtube.com/watch?v=EGQh5SZctaE) +- [What are programming languages](https://hackr.io/blog/what-is-programming-language) + +There are various languages, each made to fulfill a certain need. For example, Microsoft developed a language called [C#](https://www.youtube.com/watch?v=paJUbVeKEOU) in order to make applications for computers that run a Windows operating system. The language of C# is able to easily "talk" with the preexisting software. + +You will be learning JavaScript, a language that has been made to "talk" to web browsers (Google Chrome, Mozilla Firefox, Safari, Internet Explorer, etc.). + +Read the following article to learn more about different languages and their uses: + +- [14 Programming Languages Explained](https://mikkegoes.com/14-programming-languages-explained/) + +## 1. What is web development? + +In HackYourFuture we focus on `web programmming` (also known as `web development`): writing code that creates websites and web applications. Look at the following video to learn about what you'll be doing: + +- [What does a web developer do?](https://www.youtube.com/watch?v=GEfuOMzRgXo) + +## Web development vs. software development + +The field of programming is broad. As a software developer (a general term for anyone that writes code to create software) there are several career paths you might take. The following are some of the biggest: + +1. **Web**. Developing websites and web applications to be accessed and used in the browser +2. **Mobile**. This refers mostly to Android and iOS application development +3. **Desktop**. Every application on your computer has been made by desktop developers +4. **Data science**. Writing custom programs to extract patterns from big piles of data is what this developer does +5. **Gaming**. Game developers work with a variety of designers, artists and testers to realize a video game +6. **Quality Assurance**. Applications need to be tested, and these developers write tests that check for the correct working of any piece of code + +Read the following article to read more about different career paths: + +- [Software Development Career Paths](https://simpleprogrammer.com/software-development-career-paths/#title-career-developer-options) + +Note: once you've chosen a certain track it doesn't mean you can't try out any other! If anything, you are encouraged to explore and see what fits your taste, while building your career :) + +### Web development vs. web design + +You might have heard these terms used interchangeably. They are, however, two different things. A web developer writes code and handles the logical, technical side. A web designer decides how things are going to look and handles the creative side. The following video will explain this more clearly: + +[Web Developer vs. Web Designer](https://www.youtube.com/watch?v=bDtxF7qSofg) + +### Websites vs. web applications + +Before we get started with the meat of the module (which is JavaScript), we need to make a small but important distinction: are we going to make websites or web applications? For non-developers, there is no difference but for you as a developer you must know what it is that you'll be producing. + +The difference between a website and a web application is the difference between [Wikipedia](https://www.wikipedia.org) and [Facebook](https://wwww.facebook.com). In Facebook, the data shown changes depending on the user. If you are logged in, you'll see different things than that I will. However, on Wikipedia the information will always be the same, for both you and me. + +In other words, we're talking about `static`(= website) versus `dynamic` (= application) sites: a static site always has the same information and serves only to be information, while a dynamic site changes the data shown to the user depending on who it is and what their interactivity on the page is. + +Read the following articles to learn more about this: + +- [Website vs. Web Application](https://www.seguetech.com/website-vs-web-application-whats-the-difference/) +- [Static vs. dynamic websites](https://www.youtube.com/watch?v=4sP7fp3cp24) + +## 3. What is JavaScript? + +JavaScript is a programming language. We use it to communicate with the browser, software that allows us to access the Internet and open webpages. It is essential to learn in order to become a web developer. + +You've already learned what HTML and CSS do. Javascript is the third part that makes the circle complete. If we liken the three to the human body, we could say that HTML provides the skeleton with all the basic content, CSS makes the skin/shape to determine the look, and JavaScript is the brain and muscles to allow for interactivity. + +![Human Body](./../assets/humanbody.jpg) + +The main use for JavaScript is to make your webpage interactive: for example, if you click a button it will open a popup. Or if you scroll over an image, it changes its color. + +Check the following resources to learn more about it: + +- [What is JavaScript?](https://www.youtube.com/watch?v=nItSSTwBvSU) +- [What does JavaScript do and what is it used for?](https://www.youtube.com/watch?v=OSWppEa2Zac) + +## 4. What are variables? + +A `variable` is a box that contains a piece of information, to be saved for later use. You give it a name that describes what its contents are, and to also refer to it at a later point. + +- [Beginner Programming Concepts - What's a Variable? + ](https://www.youtube.com/watch?v=Jvrszgiexg0) + +### The keywords: let, const, var + +The concept of a `variable` is a central concept within programming. It's applied the same way across almost all programming languages. In JavaScript we apply it by using a special `keyword`, a word that is reserved by the language because it has a special meaning. + +The keywords are `var`, `let` and `const`. + +Read more about this in the following article: + +- [Variables](https://github.com/HackYourFuture/fundamentals/blob/master/fundamentals/variables.md) + +A variable always contains a `value`: the piece of information that you want to save and refer to at a later stage. Read more about this here: + +- [Values](https://www.github.com/hackyourfuture/fundamentals/blob/master/fundamentals/values.md) + +When creating variables, it's important to think about the right name to give it. It should always reflect what "type" of data it contains and what its purpose is. You (and other developers that will read your code) should be able to read a variable name and know what its purpose is. + +Why do we need variables? You'll be using variables **to manipulate its content** (the value inside the variable). Why would you want to do this? For most of the time, you want to perform some kind of calculation. The most basic example is the following: + +```js +const one = 1; +const two = one + one; +``` + +Here we have assigned to a new variable the calculation `one` plus `one`. Why have we put the end result into a new variable? It is because the result of the calculation will **not be remembered** later. Memory works differently in computers: after a calculation is finished a computer thinks its job is done. The result will not exist after, unless explicitly captured within a variable. + +This is something that you will learn when you start coding yourself. If you can't wait you can already look at the [homework](./MAKEME.md). + +## 5. What are data types? + +A data type is a category of data. It tells the code interpreter what kind of data it is reading so it knows how to process and optimally store it in memory. + +An example of this is the `Number` type. In most programming languages, when it reads the number `2` it doesn't know that it's a number. It needs to be told that the character `2` is of the `Number` data type. + +## 6 Basic types + +There are about `6 basic data types` in JavaScript: + +- `String` +- `Number` +- `Boolean` +- `Object` +- `Array` +- `Function` + +A data type, or data structure, is a way of organizing information. Computers need to know how to look at any piece of information, and it can interpret it only if it fits into one of the aforementioned data types. + +You can read more about them in the following article: + +- [JavaScript Data Types](https://www.tutorialrepublic.com/javascript-tutorial/javascript-data-types.php) +- [JS Data Types](https://www.w3schools.com/js/js_datatypes.asp) +- [Variables & Data Types](https://www.youtube.com/watch?v=Hrd3SfCCXZw) + +Why do you need to know this? Again, this goes back to computers not being very smart: it needs to know **exactly** how to look at things, what to do with it and in what order. + +In JavaScript, the data types allow us to store various types of information, and perform manipulations on them. You'll learn more about them at a later stage. + +## Extra resources + +If you feel like you need more information to fill in the gaps of your understanding, check out the following resources to learn more about the basics of JavaScript: + +- [Introduction to JavaScript Development](https://www.udemy.com/refactoru-intro-js) + +## Finished? + +Are you finished with going through the materials? You're doing great! If you feel ready to get practical, click [here](./MAKEME.md). diff --git a/Week2/LESSONPLAN.md b/Week2/LESSONPLAN.md new file mode 100644 index 000000000..25a10f1eb --- /dev/null +++ b/Week2/LESSONPLAN.md @@ -0,0 +1,262 @@ +# Lesson Plan JavaScript1 Week 2 + +## Agenda + +The purpose of this class is to introduce to the student: + +- The difference between statements & expressions +- What are operators +- What are loops +- What are conditional statements + +## Core concepts + +FIRST HALF (12.05 - 13.30) + +## 1. Q&A about last week's concepts & homework + +### Explanation + +- static vs. dynamic websites +- Variables in JavaScript: `var`, `let`, `const`, declaration, initialization, assignment +- Basic Data Types in JavaScript: `number`, `string`, `boolean`, `undefined`, `null` +- Compound Data Types in JavaScript: `array`, `object` + +### Exercise + +Let the students explain the concepts themselves. + +## 2. The difference between statements & expressions + +### Explanation + +An expression is a piece of code that resolves to a value (becomes a value) + +A statement is an instruction + +### Example + +#### Expressions + +- `sum(a, b)` +- `a` +- `a > 4 ? "yes" : "no"` +- `a + b` +- `a && b || c` + +#### statements + +- `let x;` +- `if (a > 4) { console.log("larger than 4"); } else { console.log("not larger than 4"); }` + +### Exercise + +#### Indicate for each of these whether it is an expression or a statement: + +1. `l` +2. `l = 4;` +3. `l == 4` +4. `if (l == 4) { console.log("yes"); }` +5. `console.log("yes");` +6. `"yes"` +7. `console.log(l == 4 ? "yes" : "no")` +8. `function a() { return 4; }` +9. `let a = function () { return 4; }` + +#### Given the following code: + +```js +let s = 'Hello'.toLowerCase(); +let l = s.length; + +function sum(a, b) { + return a + b; +} +let max = function(a, b) { + return a > b ? a : b; +}; + +let s1 = sum(4, 5); +let s2 = 4 + 5; + +if (s2 == s1) { + console.log('same'); +} else { + console.log('not same'); +} +``` + +List 5 statements from all 11 _statements_ in the code above + +List 5 expressions of all 28 _expressions_ in the code above (BONUS!) + +### Essence + +It's important to know the difference between expressions and statement because: + +1. It will give you an overview on what the code is about (is it an instruction or is code that resolves to a value) +2. While writing code you'll not mix up the two and therefore make sure that you do not write wrong code. + +## 3. What are operators (comparison, arithmetic, logical, assignment) + +### Explanation + +- Arithmetic Operators + - take numerical values (either literals or variables) as their operands and return a single numerical value. + - `19 + 13`, `126 / 3`, `397 % 71` +- Comparison Operators + - Two different types of comparison operators; They will always return a logical value, + - Equality Operators + - checks if the operands are 'the same' + - difference in '=' '==' '===' + - Relational Operators + - checks if the specific relation between two operands is true or false + - `>`, `<`, `<=`, `>=` + + +- Logical Operators + - Mostly 'comparing' boolean values, but it can be used with any type. + - `true || false`, `false && true`, `!true` + +- Assignment Operators + - assigns a value to its left operand based on the value of its right operand. The simple assignment operator is equal '=' + - `+=`, `-=`, `*=`, `/=` + +(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators) + +### Example + +https://www.tutorialsteacher.com/javascript/javascript-operators + +### Exercise + +See example + +### Essence + +Operators are very important in a programming language, because this is how we manipulate values. +In fact, operators are the building blocks of all possible actions. + +SECOND HALF (14.00 - 16.00) + +## 4. What are loops (do/while & for loop) + +### Explanation + +Programming loops are about doing the same thing over and over again, without typing the code over and over again. Another term for that is: iteration + +Wikipedia: In most computer programming languages, a while loop is a (control flow) statement that allows (a block of) code to be executed repeatedly based on a given Boolean condition. + +### Example + +```javascript +``` + +### Exercise + +Make a for loop with a do-while loop + +### Essence + +In programming you have to do a lot of (almost) similar calculations over and over again. Using loops makes it easier (and less boring) to code. Next to that it makes sure the the code is much more compact. + +You can check: https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Looping_code as well. underneath the paragraph: 'Why bother' + +## 5. What are conditional statements (if/else & switch) + +### Explanation + +The normal order of execution of statements in a computer program is in straight-line order, from top to bottom. However, sometimes it is desirable to execute one or more statements conditionally, i.e. depending on whether some condition – determined by the state of your program – holds true (Boolean expression). + +In its simplest form the `if` statement looks like this: + +```js +if () { +} +``` + +Then we have: + +```js +if() { +} else { +} +``` + +At last we have: + +```js +if() { +} else if { +} +``` + +The switch statement can sometimes be a useful alternative to a long list of if statements. This is the case when the condition is an expression that can be decomposed into a number of distinct values or cases, as shown in the example below. +Depending on the value of the expression specified in the `switch` clause, one of the `case` statement blocks is executed. Each statement block should end with a `break` statement to ensure that a `case` doesn't 'fall through' into the next `case`. + +The `default` statement at the end is executed when none of the preceding cases hold true. The `default` statement is not strictly required, but is a best practice to always specify one. + +### Example + +```js +if (distance < 10) { + console.log('I will take the bike.'); +} +``` + +```js +const hyfModule = 'JavaScript-1'; +let message = ''; + +switch (hyfModule) { + case 'HTML/CSS': + message = 'In this module you will learn HTML and CSS.'; + break; + case 'JavaScript-1': + message = 'In this module you will learn Git and JavaScript basics.'; + break; + case 'JavaScript-2': + message = 'In this module you will learn about JavaScript in the browser with HTML and CSS.'; + break; + case 'JavaScript-3': + message = 'In this module you will learn about Async and API calls.'; + break; + case 'Node': + message = 'This module is about building server and CLI applications using Node.'; + break; + case 'Database': + message = 'In this module is about Relational and Non-Relational Data and Database Systems.'; + break; + case 'React': + message = 'In this module you will to build Single Page Applications using React.'; + break; + case 'Project': + message = 'In this final module you will do your graduation project.'; + break; + default: + message = 'This module is unknown: ' + hyfModule; +} + +console.log(message); +``` + +### Exercise + +Create a Switch/Case that will log the season based on the month. + +```javascript +const month = 'January'; +let season = ''; + +switch (month) { + case 'January': + season = 'winter'; + break; +} + +console.log(season); // 'winter' +``` + +https://developer.mozilla.org/nl/docs/Web/JavaScript/Reference/Statements/if...else + +### Essence diff --git a/Week2/MAKEME.md b/Week2/MAKEME.md new file mode 100644 index 000000000..abc8df3da --- /dev/null +++ b/Week2/MAKEME.md @@ -0,0 +1,179 @@ +# Homework JavaScript1 Week 2 + +## **Todo list** + +1. Practice the concepts +2. JavaScript exercises +3. Code along +4. PROJECT: Grade calculator + +## **1. Practice the concepts** + +In this section you will be doing interactive exercises, that will allow you to practice with the concepts you've learned about this week! + +- Do all parts of [Codecademy: Arrays](https://www.codecademy.com/courses/introduction-to-javascript/lessons/arrays) (Signup required!) +- Do 5 exercises of [FreeCodeCamp: Basic data structures](https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-data-structures) + +## **2. JavaScript exercises** + +> Inside of your `JavaScript1` fork and inside of the `Week2` folder, create a folder called `homework`. Inside of that folder, create a folder called js-exercises. For all the following exercises create a new .js file in that folder (5 files in total). Make sure the name of each file reflects its content: for example, the filename for exercise one could be removeComma.js. + +> For all the following exercises create a new .js file. Try to find a proper name for each file or make a small comment about what it does inside for future reference. + +> Start each file off with the string `'use strict'` at the top. + +**Exercise 1: Remove the comma** + +Consider the following string: + +```js +let myString = 'hello,this,is,a,difficult,to,read,sentence'; +``` + +Follow the steps: + +1. Add the variable to your file. +2. Log the length of `myString`. +3. The commas make that the sentence is quite hard to read. Find a way to remove the commas from the string and replace them with spaces. (use Google!) +4. After replacing the commas, log `myString` to see if you succeeded. + +Expected result in the console: `hello this is a difficult to read sentence` + +**Exercise 2: The even/odd reporter** + +Report whether or not a number is odd/even! + +1. Create a `for` loop, that iterates from 0 to 20. +2. Create a conditional statement that checks if the value of the counter variable is odd or even. +3. If it's odd, log to the console `The number [PUT_NUMBER_HERE] is odd!`. +4. If it's even, log to the console `The number [PUT_NUMBER_HERE] is even!`. + +**Exercise 3: The recipe card** + +Ever wondered how to make a certain meal? Let's create a recipe list with JavaScript! + +1. Declare a variable that holds an empty object literal (your meal recipe). +2. Give the object 3 properties: a `title` (string), a `servings` (number) and an `ingredients` (array of strings) property. +3. Log each property out separately, using a loop (for, while or do/while) + +Expected result: + +```console +Meal name: Omelette +Serves: 2 +Ingredients: 4 eggs, 2 strips of bacon, 1 tsp salt/pepper +``` + +**Exercise 4: The reading list** + +Keep track of which books you read and which books you want to read! + +Follow the steps: + +1. Declare a variable that holds an array of 3 objects, where each object describes a book and has properties for the `title` (string), `author` (string), and `alreadyRead` (boolean indicating if you read it yet). +2. Loop through the array of books. +3. For each book, log the book title and book author like so: "The Hobbit by J.R.R. Tolkien". +4. Create a conditional statement to change the log depending on whether you read it yet or not. If you read it, log a string like `You already read "The Hobbit"` right after the log of the book details +5. If you haven't read it log a string like `You still need to read "The Lord of the Rings"` + +**Exercise 5: Who wants a drink?** + +You're at a party and you feel thirsty! However, you've got 5 friends who are also in need of a drink. Let's go get them a drink. + +1. Declare a variable that holds an empty array, called `drinkTray`. + +There are 3 different types of drinks: + +```js +const drinkTypes = ['cola', 'lemonade', 'water']; +``` + +2. Create a loop that runs 5 times. On each iteration, push a drink into the `drinkTray` variable. The `drinkTray` can only hold at most two instances of the same drink type, for example it can only hold 2 colas, 2 lemonades, 2 waters. + +```js +// Expected result: +const drinkTray = ['cola', 'cola', 'lemonade', 'lemonade', 'water']; + +// 'Hey guys, I brought a cola, cola, lemonade, lemonade, water!' +``` + +3. If there are already two instances of a `drinkType` then start with the next drink in the array. +4. Your `drinkTray` should contain 2 cola, 2 lemonade and 1 water. +5. Log to the console: "Hey guys, I brought a [INSERT VALUES FROM ARRAY]!" (For example: "Hey guys, I brought a cola, cola, lemonade, lemonade, water!") + +Test out your code using `node` in the command line! + +## **3. Code along** + +> Create a new GitHub repository for each of these projects. They are portfolio pieces! + +In the following 2 projects you'll be flexing your HTML/CSS skills again, together with writing JavaScript code. They are similar in structure and logic, so be sure to spot the similarities! + +It's ok if you don't understand exactly what's happening here. Just follow along and try to understand: ask yourself questions about what the developer is doing and think about every line of code. + +**Project 1: Temperature Converter** + +This project will teach you how to convert temperature from one scale to another in real-time! + +In the first part you'll be building the basic frontend, which means the way the page is going to look using only HTML/CSS. In the second part you'll be writing the logic that will allow a user to convert the temperature from one temperature scale to another (i.e. Celsius to Fahrenheit) + +- [Temperature Converter Pt. I](https://www.youtube.com/watch?v=EHclqGV_KME) +- [Temperature Converter Pt. II](https://www.youtube.com/watch?v=8mRGfLL1nzE) + +**Project 2: Weight Converter** + +In the following tutorial you'll learn how to make a Weight Converter application. You'll make use of HTML, CSS and JavaScript. At first you'll be building the basic layout of the frontend (the HTML & CSS). After you'll start writing the JavaScript logic that will `convert pounds into grams`. + +In order to speed up development you'll be using a CSS framework: [Bootstrap 4](https://www.getbootstrap.com). While coding along, have a look through the documentation in order to get familiar with the different class names to see what they do. + +- [Weight Converter App](https://www.youtube.com/watch?v=7l-ZAuU8TXc) + +## **4. PROJECT: Grade calculator** + +> Every week ends with a project you have to build on your own. Instead of getting clear-cut instructions, you'll get a list of criteria that your project needs to measure up to. + +In this project you'll write a `function` that calculates grades, based on the American grading system! Let's say a student did a test and they got a 60 out of 100, this `function` will: + +1. convert the score into a percentage +2. calculate what grade corresponds with that percentage, and +3. shows in the command line the result: the grade and the percentage + +In this example this is what we would expect the `function` to return in the command line: + +```markdown +You got a D (60%)! +``` + +When writing the `function`, make use of the following grade scores: + +```markdown +Grade A (90% - 100%) +Grade B (80% - 89%) +Grade C (70% - 79%) +Grade D (60% - 69%) +Grade E (50% - 59%) +Grade F (0% - 49%) +``` + +These are the requirements your project needs to fulfill: + +- Make a JavaScript file with a name that describes its contents +- Use either a switch or if/else statement +- Write at least 2 comments that explain to others what a line of code is meant to do +- Make the return value of the function a template string, so you can insert variables! +- Use `node` from the command line to test if your code works as expected + +Good luck! + +## **SUBMIT YOUR HOMEWORK!** + +After you've finished your todo list it's time to show us what you got! The homework that needs to be submitted is the following: + +1. JavaScript exercises +2. PROJECT: Grade calculator + +Upload both to your JavaScript1 repository forked to your personal account in GitHub. Make a pull request to the [HackYourHomework/JavaScript1](https://www.github.com/hackyourhomework/javascript1). + +> Forgotten how to upload your homework? Go through the [guide](../hand-in-homework-guide.md) to learn how to do this again. + +_Deadline Saturday 23.59 CET_ diff --git a/Week2/README.md b/Week2/README.md index b24c5bc24..c9a882e9c 100644 --- a/Week2/README.md +++ b/Week2/README.md @@ -1,24 +1,100 @@ -# Lecture two - -# Covered in class: - -## Homework: - * Update your CV: - 1. Remove sensitive personal information. You can link to your LinkedIn account for instance if you want people to be able to reach you - 2. Look at the feedback from the last module (HTML/CSS) change your CV to reflect this feedback. - 3. Validate your html using the W3c Vaidator https://validator.w3.org/ - * Complete the following codecamp assignments: - * Start at https://www.freecodecamp.com/challenges/write-reusable-javascript-with-functions - * And make the next couple assignments until your reach: Assignment with a Returned Value - * Add a useful function to your website:
- Write a js feature that follows the following rules - 1. It takes user input on a website (look up input fields) - 2. It uses that input as parameters for a function - 3. The function does something with the parameters and returns a value using 'return' - 4. The return value is used on the website. - * For instance: Create a function that allows people to input a certain product they eat or drink every day and then asks how long they expect to live (for instance someone smokes one pack of cigarettes a day and expects to live 25 more years) then they might spend 1 X priceOfPack x 365 x lifeExpectancy euros on that product - * Be creative. If your idea is too complex to finish, don't worry, this exercise is really about trying to write some code yourself and applying what you've learnt. - * Try to solve Unmesh' challenge: - Assignment for “for loops” : - * Print ’n’ lines of a Pascal’s triangle. - * Hand in your homework in Trello +# Reading Material JavaScript1 Week 2 + +## Agenda + +These are the topics for week 2: + +1. Statements vs. Expressions +2. Loops +3. Control Flow +4. Operators +5. Conditional statement +6. Naming conventions + +## 0. Video Lectures + +Your teacher Uday has made video lectures for this week's material. You can find them here: [Videos 11 - 20](https://www.youtube.com/playlist?list=PLVYDhqbgYpYUiqH8IxLJ5qomkEGMzes1q) + +HYF Video + +## 1. Statements vs. Expressions + +A lot of programming is nothing different from regular human communication. When conversing with another person, we often use language in various ways: to ask questions, make statements or simply express yourself about what's going on. + +This is the same in programming. A difference is that it's done in abstract code. Another difference is that a programming statement is an instruction, while a programming expression leads directly to a value (and are usually different parts of a statement). + +To learn more about statements vs. expression, research the following resources: + +- [Expressions vs. Statements in JS](https://www.youtube.com/watch?v=WVyCrI1cHi8) +- [Statements vs. Expressions](https://github.com/HackYourFuture/fundamentals/blob/master/fundamentals/statements_expressions.md) + +## 2. Loops + +A loop is a sequence of instructions that is continually repeated until a certain condition is fulfilled. This condition could either be a specified number or when a desired value is found or not. + +In programming, a loop is meant to be used in case there's a repetitive task that needs to be done. + +Learn more about loops here: + +- [JavaScript Loops](https://www.youtube.com/watch?v=s9wW2PpJsmQ) +- [Loops](https://github.com/HackYourFuture/fundamentals/blob/master/fundamentals/loops.md) + +## 3. Control Flow + +Almost all European languages are read from left to right. In Arabic and Hebrew this is the other way around: from right to left. + +In the language of JavaScript this goes from top to bottom, left to right. This is called the `control flow`: the order in which the computer executes statements in a script. The `control` parts refers to the ability to execute something by the computer, while the `flow` part refers to the causal chain between the execution of one action to another. + +> The term `flow` is a general term meaning a specific, repeatable order of actions. In your working life you'll hear the term `workflow`, which in that case refers to the different actions necessary to complete a business activity. + +There is one important distinction between spoken language and programming languages: in programming languages the order in which the code is read can change, depending on various `control statements` (`if`, `for/while/do-while loop` or `switch`). + +Learn more about control flow here: + +- [Introduction to Programming - Control Flow](https://www.youtube.com/watch?v=nBj2nJup8xU) +- [Control flow](https://dev.to/mugas/control-flow-in-javascript-246l) + +## 4. Operators + +If you've ever taken a mathematics class you are familiar with symbols like `+`, `-`, `/` and `=`. These symbols are recognized by the computer and are called `operators`. They can be used to perform calculations (with numbers) or to determine whether or not something is true (more on that in the next section). + +Check the following resources to learn more about their importance: + +- [Different Types of Operators in JavaScript](https://www.youtube.com/watch?v=FZzyij43A54) +- [Operators](https://github.com/HackYourFuture/fundamentals/blob/master/fundamentals/operators.md) + +## 5. Conditional statement + +Computers only function by logical rules: whether something is true or not determines if an instructions gets executed or not. This logical process is expressed in a `conditional statement` and goes like this: if _this happens_, then _that happens_. Or in code: + +```js +if () { + // then this will happen +} +``` + +A condition is put in the `( )` and it needs to evaluate to `true` or `false` (also known as `Boolean` values). If the condition is true, then whatever is inside the `{ }` will be executed. + +What happens when the condition is false? For that we have the `else { }` block. If the condition is false, then whatever is inside the else will be executed: + +```js +if() { + +} else { + +} + +``` + +## 6. Naming conventions + +A naming convention is a rule that every developer should hold themselves to when creating variable or function names. This is important, because writing code should be done in a **readable** way: you should be able to understand what a certain variable or function does just by looking at its name. + +Read about the different naming conventions for JavaScript here: + +- [Naming Conventions in Programming](https://blog.jsecademy.com/naming-conventions-in-programming/) +- [Naming conventions](https://github.com/HackYourFuture/fundamentals/blob/master/fundamentals/naming_conventions.md) + +## Finished? + +Are you finished with going through the materials? You're doing great! If you feel ready to get practical, click [here](./MAKEME.md). diff --git a/Week2/code_examples/conditional_example_1.js b/Week2/code_examples/conditional_example_1.js new file mode 100644 index 000000000..821665e90 --- /dev/null +++ b/Week2/code_examples/conditional_example_1.js @@ -0,0 +1,33 @@ +var code = 1; +let someOtherVariable = 'Hello'; +const PROGRAM_NAME = 'conditional_test1.js'; + +let color = 'BLACK'; +let age = Math.PI; + +console.log(age); +console.log(age = '0'); // What will this line print? +console.log(age == 0); // What will this line print? +// The result of a logical operator like == === < > <= >= || && is a BOOLEAN (true, false) +console.log(age === 0); // What will this line print? +// === checks the TYPE and VALUE of the variable + +if (code === 1) { + console.log("a " + color + ((age = 0 || age > 0) ? " used" : " new") + " car") +}; + +if (code === 1) { + console.log("a " + color + ((age <= 1 || age > 1) ? " used" : " new") + " car") +}; + +// Maybe simpler and easier to read? +if (code == 1) { + var carState; + if (age > 0) { + carState = " used "; + } else { + carState = " new "; + } + console.log("a " + color + carState + " car"); +} + diff --git a/Week2/code_examples/conditional_example_2.js b/Week2/code_examples/conditional_example_2.js new file mode 100644 index 000000000..2c297291b --- /dev/null +++ b/Week2/code_examples/conditional_example_2.js @@ -0,0 +1,24 @@ + +condition = true; +// Conditional block + if (condition) { + // Do this thing if condition is true + console.log('condition is true'); + } else if (condition2) { + // Do this if condition2 is true + console.log('condition2 is true'); + } else { + // finally - end up here + console.log('condition and condition2 are false'); + } + + +// Programmers at some point in their career get LAZY +// They don't want to type so much +// So they make things like vi and shortcuts + +// Here's the shortcut for conditional logic - TRY TO NEVER USE IT + +// condition ? true thing : false thing +let x = 3; +(x > 2) ? console.log('x is greater than 2') : console.log('x is less than or equal to 2'); diff --git a/Week2/code_examples/debug_example.js b/Week2/code_examples/debug_example.js new file mode 100644 index 000000000..61f5f3d17 --- /dev/null +++ b/Week2/code_examples/debug_example.js @@ -0,0 +1,38 @@ +// Three ways to declare (and initialize) variables +var code = 1; +let someOtherVariable = 'Hello'; +const PROGRAM_NAME = 'debug_example.js'; + +let color = 'BLACK'; +let age = Math.PI; + +console.log(age); +console.log(age = '0'); // What will this line print? +console.log(age == 0); // What will this line print? +// The result of a logical operator like == === < > <= >= || && is a BOOLEAN (true, false) +console.log(age === 0); // What will this line print? +// // === checks the TYPE and VALUE of the variable +function printCarInfo(code, color, age) { + if (code === 1) { + let carState = ' used'; + if (age === 0) { + carState = ' new'; + } + console.log('a ' + color + carState + ' car'); + }; +} +// What is the difference between '' and "" +// I use ' because I don't have to press SHIFT to get " +printCarInfo(code, color, age); +printCarInfo(1, 'PINKISH BLUE ORANGE(1)', 0); // expect 'a PINKISH BLUE ORANGE(1) new car' +printCarInfo(0, 'PINKISH BLUE ORANGE(2)', 0); // expect nothing +printCarInfo(1, 'Green', 0); // expect 'a Green new car' +printCarInfo(1, 'Green', 1); // expect 'a Green used car' +printCarInfo(1, 'Green', -999999); // +printCarInfo(1, 'Green', 1000000); // +printCarInfo(-1, null, -999999999); // expect nothing +printCarInfo('1', null, -999999999); // expect nothing +printCarInfo(1, null, -999999999); // expect 'a null used car' +printCarInfo(1, undefined, -999999999); // expect 'a undefined used car' + printCarInfo(1); // ?????? WTF ????? expect 'a undefined used car', 'an error', 'an exception' 'a used car' +printCarInfo(2, 'Cyan', 1); // Expect nothing - code is not === 1 diff --git a/Week2/code_examples/initialization_example.js b/Week2/code_examples/initialization_example.js new file mode 100644 index 000000000..96cc2dc55 --- /dev/null +++ b/Week2/code_examples/initialization_example.js @@ -0,0 +1,20 @@ +var testValue = ''; +console.log('var testValue = \'\'; gives: ', testValue); + +var testValue = 0; +console.log('var testValue = 0; gives: ', testValue); + +var testValue = null; +console.log('var testValue = null; gives: ', testValue); + +var testValue = undefined; +console.log('var testValue = undefined; gives: ', testValue); + +var testValue; +console.log('var testValue; gives: ', testValue); + +var testValue = ''; +console.log('var testValue = \'\'; gives: ', testValue); + +var someVar = testValue || 'Default'; +console.log('var someVar = testValue || \'Default\' = 0; gives: ', someVar); diff --git a/Week3/LESSONPLAN.md b/Week3/LESSONPLAN.md new file mode 100644 index 000000000..50a1ce2f7 --- /dev/null +++ b/Week3/LESSONPLAN.md @@ -0,0 +1,126 @@ +# Lesson Plan JavaScript1 Week 3 + +## Agenda + +The purpose of this class is to introduce to the student: + +- What is a function (ES5 only) +- Wat is scope (global, functional, block) +- How to combine variables, loops & functions + +## Core concepts + +FIRST HALF (12.00 - 13.30) + +## 1. Q&A about last week's concepts & homework + +- Variables +- Basic data types (`string`, `number`, etc) +- Compound data types (`array`, `object`) +- Branching constructs + - `if..else` +- Looping constructs + - `for` + - `for..of` + - `for..in` + - `do..while` +- Operators (arithmetic, comparison, eg `+`, `*`, `&&`, `||`, etc). + +Note: You can ask students to explain a concept or summerise the last lecture themselves + +## 2. Function (ES5 only) + +### Explanation +Functions are a way to organize your code in to re-usable chunks. + +> People think that computer science is the art of geniuses but the actual reality is the opposite, just many people doing things that build on each other, like a wall of mini stones. +> +> _-- Donald Knuth_ + +https://github.com/HackYourFuture/fundamentals/blob/master/fundamentals/functions.md +### Example +Same link as Explanation +### Exercise + +### Essence +- __Reusability__: Functions can be grouped together to make a module (or library), and then modules can be imported into your application so you can build awesome apps! +- __Abstraction__: Hide underlying details about how a piece of functionality works under the hood. You can change how things are implemented within the function without other programmers who use your function worrying aobut the exact details of how it was implemented. + +And the same link as Explanation + +SECOND HALF (14.00 - 16.00) + +## 3. Scope (global, functional, block) + +### Explanation +Scopes define the visiblity of declarations of variables and functions. + +The top level outside all your functions is called the _global scope_. Values defined in the global scope are accessible from everywhere in the code. Whereas, variables defined in local scope can only be accessed and altered inside the scope they were created. + +- `var` and `function` declarations are visible with function scope. +- `let` and `const` declarations are visible with block scope. A block can be seen as a set of statements enclosed in curly brackets({}). + +Global scope: + +- Can be a real useful tool or a nightmare. +- Useful in scenarios where we want to export JS modules, use third party libraries like jQuery etc. +- Big risk of causing namespace clashes with multiple variables with same name being created in different places. + +Local Scope: + +- Think of local scope as any new scope that is created within the global scope. +- Each function written in JavaScript creates a new local scope. +- Variables defined within a function aren't available outside it. They are created when a function starts and are _in a way_ destroyed/hidden when a function ends. + +https://github.com/HackYourFuture/fundamentals/blob/master/fundamentals/scope.md +### Example +![Scopes](../assets/scopes.png) + +```Javascript +let villan = "Joker"; // | global scope + // | +function myFunction() { // | | function scope + let hero = "Batman"; // | | + if (hero === "Batman") { // | | | block scope + let coHero = "Robin"; // | | | + console.log(hero); // | | | + console.log(coHero); // | | | + console.log(villan); // | | | + } // | | | + console.log("------") // | | + console.log(hero); // | | + console.log(coHero); // | | + console.log(villan); // | | +} // | | + // | +myFunction(); // | +``` + +And the same link as Explanation +### Exercise +What happens if we use the same variable name in different scopes? + +```Javascript +function myFunction() { + let hero = "Batman"; + if (true) { + let hero = "The Flash"; + console.log(hero); + } + console.log(hero); +} + +myFunction(); +``` +### Essence +Same link as Explanation + +## 4. How to combine variables, loops & functions + +### Explanation +### Example +### Exercise +https://github.com/yash-kapila/HYF-JS1-Week3/tree/master/src +### Essence + +_Special thanks to Jim Cramer, Yash Kapila, David Nudge for most of the content_ diff --git a/Week3/MAKEME.md b/Week3/MAKEME.md new file mode 100644 index 000000000..d76dc7c0e --- /dev/null +++ b/Week3/MAKEME.md @@ -0,0 +1,205 @@ +# Homework JavaScript1 Week 3 + +## **Todo list** + +1. Practice the concepts +2. JavaScript exercises +3. Code along +4. PROJECT: Grade calculator +5. [OPTIONAL] Extra resources + +## **1. Practice the concepts** + +In this section you will be doing interactive exercises that will allow you to practice with the concepts you've learned about this week. + +In the first course you'll learn about functions, the structure and how they're used. They are a fundamental part of understanding programming and you should become very familiar with them! + +- [Codecademy: Functions ](https://www.codecademy.com/courses/introduction-to-javascript/lessons/functions) + +In this second course you'll learn about `higher order functions`, which we'll refer to again during the [JavaScript2](https://www.github.com/HackYourFuture/JavaScript2) module. Go through it to get familiar, but don't feel like you completely have to understand it at this point. + +- [Codecademy: Higher Order Functions](https://www.codecademy.com/courses/introduction-to-javascript/lessons/higher-order-functions/) + +## **2. JavaScript exercises** + +> Inside of your `JavaScript1` fork and inside of the `Week3` folder, create a folder called `homework`. Inside of that folder, create a folder called js-exercises. For all the following exercises create a new .js file in that folder (5 files in total). Make sure the name of each file reflects its content: for example, the filename for exercise one could be giveCompliment.js. + +> In each file, start off with the string 'use strict'. This will make sure the code interpreter will enforce stronger rules when looking at your code. + +**Exercise 1: You are amazing, Noer!** + +There is no better way to start your day then with a compliment! + +1. Write a function named `giveCompliment` + +- It takes 1 argument: your name +- Inside the function define a variable that holds an array, `compliments`, with 10 strings. Each string should be a compliment, like `"great"`, `"awesome"` +- Write code that randomly selects a compliment +- Return a string: "You are [COMPLIMENT], [YOUR_NAME]! + +2. Call the function three times, giving each function call the same argument: your name. + +```js +// Expected output +giveCompliment('Noer'); // Returns "You are amazing, Noer!" +giveCompliment('Noer'); // Returns "You are great, Noer!" +giveCompliment('Noer'); // Returns "You are supersmart, Noer!" +``` + +**Exercise 2: Dog years** + +You know how old your dog is in human years, but what about dog years? Let's calculate it! + +1. Write a function named `calculateDogAge`. + +- It takes 1 argument: your (fictional) puppy's age (number). +- Calculate your dog's age based on the conversion rate of `1 human year to 7 dog years`. +- Return a string: "Your doggie is [CALCULATED_VALUE] years old in dog years!" + +2. Call the function three times with different sets of values. + +```js +// Expected output +calculateDogAge(1); // Returns "Your doggie is 7 years old in dog years!" +calculateDogAge(2); // Returns "Your doggie is 14 years old in dog years!" +calculateDogAge(3); // Returns "Your doggie is 21 years old in dog years!" +``` + +**Exercise 3: Be your own fortune teller** + +Why pay a fortune teller when you can just program your fortune yourself? + +1. Create 4 arrays, `numChildren`, `partnerNames`, `locations` and `jobs`. Give each array 5 random string values that have to do with the name of the variable +2. Write a function named `tellFortune`. + +- It takes 4 arguments: number of children (number), partner's name (string), geographic location (string), job title (string). +- Randomly select values from the arrays. +- Return a string: "You will be a [JOB_TITLE] in [LOCATION], married to [PARTNER_NAME] with [NUMBER_KIDS] kids." + +3. Call the function 3 times, by passing the arrays as the argument. + +```js +// Expected output +const numChildren = [...]; +const partnerNames = [...]; +const locations = [...]; +const jobs = [...]; + +tellFortune(numChildren, partnerNames, locations, jobs); // Returns "You will be a programmer in The Netherlands, married to Layla with 3 kids." +tellFortune(numChildren, partnerNames, locations, jobs); // Returns "You will be a farmer in France, married to Muhammed with 2 kids." +tellFortune(numChildren, partnerNames, locations, jobs); // Returns "You will be a teacher in The United States, married to Zara with 4 kids." +``` + +**Exercise 4: Shopping at the supermarket** + +Let's do some grocery shopping! We're going to get some things to cook dinner with. However, you like to spend your money and always buy too many things. So when you have more than 3 items in your shopping cart the first item gets taken out. + +1. Create an array called `shoppingCart` that holds the following strings: `"bananas"` and `"milk"` +2. Write a function named `addToShoppingCart` + +- It takes 1 argument: a grocery item (string) +- Add grocery item to `shoppingCart`. If the amount of items is more than 3 remove the first one in the array +- Loops through the array in order to list out the items +- Return a string: "You bought [LIST_OF_GROCERY_ITEMS]!" + +3. Call the function 3 times, each time with a different string as the argument. + +```js +const shoppingCart = ['bananas', 'milk']; + +// Expected output +addToShoppingCart('chocolate'); // Returns "You bought bananas, milk, chocolate!" +addToShoppingCart('waffles'); // Returns "You bought milk, chocolate, waffles!" +addToShoppingCart('tea'); // Returns "You bought chocolate, waffles, tea!" +``` + +**Exercise 5: Total cost is ...** + +You want to buy a couple of things from the supermarket to prepare for a party. After scanning all the items the cashier wants to give you the total price, but the machine is broken! Let's write her a `function` that does it for her instead! + +1. Create an object named `cartForParty` with 5 properties. Each property should be a grocery item (like `beers` or `chips`) and hold a number value (like `1.75` or `0.99`) +2. Write a function called `calculateTotalPrice` + +- It takes 1 argument: an object that contains properties that only contain number values +- Loop through the object and add all the number values together +- Return a string: "Total: €[TOTAL_PRICE_ITEMS]" + +3. Call the function 1 time, giving it the object `cartForParty` as an argument + +```js +const cartForParty = { ... } + +// Expected output +calculateTotalPrice(cartForParty); // Returns "Total: €10.75" +``` + +## **3. Code along** + +> Create a new GitHub repository for this project. It's a portfolio piece! + +In this project you'll be building a simple meditation application, that will allow you to set a timer, loop a video and play a song! + +You'll be working with the