|
2 | 2 |
|
3 | 3 | ## Todo list
|
4 | 4 |
|
5 |
| -1. JavaScript exercises |
6 |
| -2. s |
7 |
| - |
| 5 | +1. Get to know |
| 6 | +2. JavaScript exercises |
8 | 7 | 3. Code along
|
9 | 8 | 4. PROJECT:
|
10 | 9 |
|
11 |
| -### 1. JavaScript exercises |
| 10 | +### 1. Get to know |
| 11 | + |
| 12 | +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. |
| 13 | + |
| 14 | +In the following exercises you'll learn how to use different JavaScript concepts to solve common computational problems: |
| 15 | + |
| 16 | +- [Learn-js](https://www.learn-js.org/). Do all the `Learn the basics` exercises. |
| 17 | +- [Codecademy: Introduction to JavaScript](https://www.codecademy.com/learn/introduction-to-javascript/modules/learn-javascript-introduction). Do all the exercises (#1 to #10). |
| 18 | +- [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. |
| 19 | + |
| 20 | +### 2. JavaScript exercises |
| 21 | + |
| 22 | +Inside of your `JavaScript1` fork, create a folder called `week1`. 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`. |
| 23 | + |
| 24 | +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. |
| 25 | + |
| 26 | +> 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. |
| 27 | +
|
| 28 | +**Exercise 1: Hello world!** |
| 29 | + |
| 30 | +Write a statement, using the `console.log()` function. Give it a string as an argument. The string should contain the message "Hello world!". |
| 31 | + |
| 32 | +Write 10 statements like these, but in different languages. |
| 33 | + |
| 34 | +For example: |
| 35 | + |
| 36 | +``` |
| 37 | +Halo, dunia! // Indonesian |
| 38 | +Ciao, mondo! // Italian |
| 39 | +Hola, mundo! // Spanish |
| 40 | +``` |
| 41 | + |
| 42 | +Using the command line, navigate to your `week1` folder and type in the following to test your code: |
| 43 | + |
| 44 | +``` |
| 45 | +node FILENAME.js |
| 46 | +``` |
| 47 | + |
| 48 | +It should show the message `Hello world!` in 10 different languages. |
| 49 | + |
| 50 | +**Exercise 2: Error debugging** |
| 51 | + |
| 52 | +Consider the following code: |
| 53 | + |
| 54 | +```js |
| 55 | +console.log('I'm awesome'); |
| 56 | +``` |
| 57 | +
|
| 58 | +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. **Correct the mistake**. |
| 59 | +
|
| 60 | +Hint: the SyntaxError message will give you some indication of what the error _might_ be, but figure out yourself how to correct it! |
| 61 | +
|
| 62 | +When done right, it should show the message `I'm awesome`. |
| 63 | +
|
| 64 | +**Exercise 3: Log the number** |
| 65 | +
|
| 66 | +Follow the steps. Make sure that each step is written on the line after. The file should have 6 lines (excluding the 'use strict') in total. |
12 | 67 |
|
13 |
| -- Codecademy [Introduction to JavaScript](https://www.codecademy.com/learn/introduction-to-javascript/modules/learn-javascript-introduction) |
14 |
| -- FreeCodeCamp [Introduction to JavaScript](https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript) |
| 68 | +1. First, _declare_ your variable `numberX`. Do not _initialize_ it (which means, don't give it a value) yet. |
| 69 | +2. Add a `console.log` statement that explains in words _what you think_ the value of `x` is, like in this example. |
| 70 | +3. Add a `console.log` statement that logs the value of `numberX`. |
| 71 | +4. Now _initialize_ your variable `numberX` with a number (also called an `integer` in computer science terms). |
| 72 | +5. Next, add a `console.log` statement that explains _what you think_ the value of `numberX` is. |
| 73 | +6. Add a `console.log` statement that logs the value of `numberX`. |
15 | 74 |
|
16 |
| -### 2. |
| 75 | +**Exercise 4: Log the string** |
| 76 | +
|
| 77 | +Follow the steps. Make sure that each step is written on the line after. The file should have 6 lines (excluding the 'use strict') in total. |
| 78 | +
|
| 79 | +1. Declare a variable `myString` and assign a string to it. Use your full name, including spaces, as the content for the string. |
| 80 | +2. Write a `console.log` statement in which you explain in words _what you think_ the value of the string is. |
| 81 | +3. Now `console.log` the variable `myString`. |
| 82 | +4. Now reassign to the variable `myString` a new string. |
| 83 | +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. |
| 84 | +6. Now console.log `myString` again. |
| 85 | +
|
| 86 | +**Exercise 5: Round a number and log it** |
| 87 | +
|
| 88 | +Follow the steps. Make sure that each step is written on the line after. The file should have 6 lines (excluding the 'use strict') in total. |
| 89 | +
|
| 90 | +1. Declare a variable `z` and assign the number 7.25 to it. |
| 91 | +2. Write a `console.log` statement in which you log the value of `z`. |
| 92 | +3. Declare another variable `a` that has the value of `z` but rounded to the nearest integer. |
| 93 | +4. Write a `console.log` statement in which you log the value of `a`. |
| 94 | +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. |
| 95 | +6. Write a `console.log` statement in which you log the value of the highest value. |
| 96 | +
|
| 97 | +**Exercise 6: Log an array of animals** |
| 98 | +
|
| 99 | +Follow the steps. Make sure that each step is written on the line after. The file should have 7 lines (excluding the 'use strict') in total. |
| 100 | +
|
| 101 | +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`. |
| 102 | +2. Write a `console.log` statement that explains in words _what you think_ the value of the array is. |
| 103 | +3. Write a `console.log` statement that logs the array. |
| 104 | +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. |
| 105 | +5. Write a `console.log` statement that logs the second array. |
| 106 | +6. Add a statement that adds another string ("Piglet)" to the array of animals. |
| 107 | +7. Write a `console.log` statement that logs the second array! |
| 108 | +
|
| 109 | +**Exercise 7: Log the length of a string** |
| 110 | +
|
| 111 | +1. Declare a variable called `mySentence` and initialize it with the following string: "Programming is so interesting!". |
| 112 | +2. Figure out (using Google) how to get the length of `mySentence`. |
| 113 | +3. Write a `console.log` statement to log the length of `mySentence`. |
| 114 | +
|
| 115 | +**Exercise 8: ** |
| 116 | +
|
| 117 | +8.0 Write a program that checks the types of two variables and prints out `SAME TYPE` if they are the same type. |
| 118 | +8.1 First declare at least four variables and assign them different data types. |
| 119 | +8.2 For each variable write a `console.log` statement that logs the value |
| 120 | +
|
| 121 | +```js |
| 122 | +let foo = 3; |
| 123 | +console.log("The value of my variable foo is: " + foo); |
| 124 | +``` |
| 125 | +
|
| 126 | +(Curious to know what a `foo` is? Check [this article](https://en.wikipedia.org/wiki/Metasyntactic_variable) on Wikipedia.) |
| 127 | +
|
| 128 | +8.3 Now write a `console.log` statement wherein you first explain in words what you think the _type_ of your variables is. |
| 129 | +8.4 Now use `typeof` to log the actual _type_ of your variables. |
| 130 | +8.5 Now compare the types of your different variables with one another. |
| 131 | +8.6 Make sure to also show a message when the variables you are comparing are not the same type. |
| 132 | +
|
| 133 | +For example: |
| 134 | +
|
| 135 | +```js |
| 136 | +let x = 9; |
| 137 | +let y = 'Hello'; |
| 138 | + |
| 139 | +if (...) { |
| 140 | + console.log('SAME TYPE'); |
| 141 | +} |
| 142 | +// TODO -> add a way of giving feedback if your variables don't have the same type |
| 143 | +``` |
| 144 | +
|
| 145 | +**Exercise 9:** |
| 146 | +
|
| 147 | +9.0 If `x` equals 7, and the only other statement is `x = x % 3`, what would be the new value of `x`? |
| 148 | +9.1 Add at least 3 `console.log` statements in which you show that you understand what `%` does. |
| 149 | +
|
| 150 | +**Exercise 10:** |
| 151 | +
|
| 152 | +10.0 Write a program to answer the following questions: |
| 153 | +10.1 Can you store multiple types in an array? Numbers and strings? Make an example that illustrates your answer. |
| 154 | +10.2 Can you compare infinities? (Not in Eyad's world) - does 6/0 === 10/0? How can you test this? |
| 155 | +10.3 Add `console.log` statements to the above program in which you show that you understand the concepts (just like you've done in the above assignments). |
17 | 156 |
|
18 | 157 | ### 3. Code along
|
19 | 158 |
|
| 159 | +We don't want to lose connection with HTML/CSS, so in the following tutorial you'll learn how to build a simple web application use HTML/CSS and JavaScript. |
| 160 | +
|
20 | 161 | ### 4. PROJECT:
|
21 | 162 |
|
22 |
| -> 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. |
| 163 | +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. |
23 | 164 |
|
24 | 165 | ## SUBMIT YOUR HOMEWORK!
|
25 | 166 |
|
26 | 167 | 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:
|
27 | 168 |
|
28 |
| -1. s |
29 |
| -2. s |
| 169 | +1. JavaScript exercises |
| 170 | +2. Project |
30 | 171 |
|
31 |
| -Upload both in a repository to GitHub and then upload the link to Trello. Go through the [guide](../hand-in-homework-guide.md) to learn how to do this. |
| 172 | +Go through the [guide](../hand-in-homework-guide.md) to learn how to do this. |
32 | 173 |
|
33 | 174 | _Deadline Saturday 23.59 CET_
|
0 commit comments