|
1 | 1 | //Level2
|
2 | 2 |
|
3 | 3 | /* Arrays
|
4 |
| - It is ordered list of values. It can keep any number of values inside. And also |
| 4 | + It is an ordered list of values. It can keep any number of values inside. And also |
5 | 5 | any type of values - numbers, strings, objects.
|
6 | 6 | Example:
|
7 | 7 | var animals = ['cat', 'dog', 'horse];
|
|
40 | 40 | var secondItem = randomThings[1]; and so on
|
41 | 41 | */
|
42 | 42 |
|
43 |
| -//TODO: get 3d element from your array favouriteFood and console.log it |
| 43 | +//TODO: get 3rd element from your array favouriteFood and console.log it |
44 | 44 |
|
45 | 45 |
|
46 | 46 |
|
|
52 | 52 | We also can replace values inside of the arrays by assigning specific item from
|
53 | 53 | the array to a new value.
|
54 | 54 | Example:
|
55 |
| - var animals = ['cat', 'dog', 'horse]; |
| 55 | + var animals = ['cat', 'dog', 'horse']; |
56 | 56 | //let's replace 'dog' with 'fish'
|
57 | 57 | animals[1] = 'fish';
|
58 |
| - //now our animals array will be ['cat', 'fish', 'horse] |
| 58 | + //now our animals array will be ['cat', 'fish', 'horse'] |
59 | 59 | */
|
60 | 60 |
|
61 | 61 | //TODO: take your array favouriteFood and replace first value with anything else.
|
62 | 62 | //console.log whole array to check
|
| 63 | +// Dont forget, that index position starts with 0 |
63 | 64 |
|
64 | 65 |
|
65 | 66 |
|
|
71 | 72 | If you want to add new value to array you can use property of array named '.push'.
|
72 | 73 | It will add value to the end of the array
|
73 | 74 | Example:
|
74 |
| - var animals = ['cat', 'dog', 'horse]; |
| 75 | + var animals = ['cat', 'dog', 'horse']; |
75 | 76 | animals.push('rabbit');
|
| 77 | + so now our array will be ['cat', 'dog', 'horse','rabbit'] |
76 | 78 | */
|
77 | 79 |
|
78 | 80 | //TODO: let's extend your list of favouriteFood and add one more value in it.
|
79 |
| -//console.log list of your food o check |
| 81 | +//console.log list of your favouriteFood and check |
80 | 82 |
|
81 | 83 |
|
82 | 84 |
|
|
86 | 88 |
|
87 | 89 |
|
88 | 90 | /* Loops
|
89 |
| - People always have been lazy and it was moving progress forward. We don't like repeat |
90 |
| - same boring actions again and again, so we are looking for the way how to improve it. |
| 91 | + People always have been lazy and it was moving progress forward. We don't like to repeat |
| 92 | + same boring actions again and again, so we are looking for ways how to improve it. |
91 | 93 | Programming is the same - for example, if I want to print 'JavaScript is awesome!' 10
|
92 | 94 | times what are my options? Of course, I can print 10 lines of code repeating same
|
93 |
| - phrase over and over again, but I also can tell computer to do it instead of me. |
94 |
| - To do it we have loops. |
| 95 | + phrase over and over again, but I also can tell computer to repeat it instead of me. |
| 96 | + For this we have loops. |
95 | 97 | Each loop should have 3 main things:
|
96 | 98 | - starting point
|
97 | 99 | - condition (finishing point)
|
98 | 100 | - counter (a step)
|
99 | 101 | If you miss one of them you can get into infinite loop!!!
|
| 102 | +
|
| 103 | + Let's look into different looping structures |
100 | 104 | */
|
101 | 105 |
|
102 | 106 |
|
|
129 | 133 | PS: i++ is a short from 'i = i + 1'
|
130 | 134 | */
|
131 | 135 |
|
132 |
| -//TODO: now, let's print every 3d number from 3 to 22 using 'for loop' |
| 136 | +//TODO: now, let's print every 3rd number from 3 to 22 using 'for loop' |
133 | 137 |
|
134 | 138 |
|
135 | 139 |
|
|
175 | 179 | */
|
176 | 180 |
|
177 | 181 | //TODO: Time has come for a classic exercise - 'FizzBuzz'. Count from 1 to 50 and print
|
178 |
| -// numbers out. If number multiple of 3 print 'Fizz', if multiple of 5 - 'Buzz', if |
179 |
| -// it is multiple of 3 and 5 - 'FizzBuzz'. |
| 182 | +// numbers out. If number is a multiple of 3 print 'Fizz', if its a multiple of 5 print 'Buzz', if |
| 183 | +// it is multiple of 3 and 5 print 'FizzBuzz', for everthing else print the number itself. |
180 | 184 | //PS: you can use arithmetic operator modulo (%) - it is remainder when dividing.
|
181 | 185 | //10 % 3 = 1 - so in 10 we have 3*3 + 1
|
182 | 186 | //16 % 4 = 0 - as in 16 we have 4*4
|
|
0 commit comments