GeezerVison is showing github.com — Convert exercises to use blocks · harsh-it2000/javascript@8a8361f
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: en/arrays/README.md +1Lines changed: 1 addition & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -5,6 +5,7 @@ Arrays are a fundamental part of programming. An array is a list of data. We can | 5 | 5 | The data in arrays are called **elements**. | 6 | 6 |
| 7 | 7 | Here is a simple array: | | 8 | + | 8 | 9 | ```javascript | 9 | 10 | // 1, 1, 2, 3, 5, and 8 are the elements in this array | 10 | 11 | var numbers = [1, 1, 2, 3, 5, 8]; | |
Collapse file Copy file name to clipboardExpand all lines: en/arrays/indices.md +5-12Lines changed: 5 additions & 12 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -11,31 +11,24 @@ var fruits = ["apple", "banana", "pineapple", "strawberry"]; | 11 | 11 | // second element. Result: banana = "banana" | 12 | 12 | var banana = fruits[1]; | 13 | 13 | ``` | 14 | | ---- | 15 | 14 |
| | 15 | +{% exercise %} | 16 | 16 | Define the variables using the indices of the array | 17 | | - | 18 | | -```js | | 17 | +{% initial %} | 19 | 18 | var cars = ["Mazda", "Honda", "Chevy", "Ford"] | 20 | 19 | var honda = | 21 | 20 | var ford = | 22 | 21 | var chevy = | 23 | 22 | var mazda = | 24 | | -``` | 25 | | - | 26 | | -```js | | 23 | +{% solution %} | 27 | 24 | var cars = ["Mazda", "Honda", "Chevy", "Ford"] | 28 | 25 | var honda = cars[1]; | 29 | 26 | var ford = cars[3]; | 30 | 27 | var chevy = cars[2]; | 31 | 28 | var mazda = cars[0]; | 32 | | -``` | 33 | | - | 34 | | -```js | | 29 | +{% validation %} | 35 | 30 | assert(honda === "Honda"); | 36 | 31 | assert(ford === "Ford"); | 37 | 32 | assert(chevy === "Chevy"); | 38 | 33 | assert(mazda === "Mazda"); | 39 | | -``` | 40 | | - | 41 | | ---- | | 34 | +{% endexercise %} |
Collapse file Copy file name to clipboardExpand all lines: en/arrays/length.md +7-14Lines changed: 7 additions & 14 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -9,23 +9,16 @@ var array = [1 , 2, 3]; | 9 | 9 | var l = array.length; | 10 | 10 | ``` | 11 | 11 |
| 12 | | ---- | 13 | | - | | 12 | +{% exercise %} | 14 | 13 | Define the variable a to be the number value of the length of the array | 15 | | - | 16 | | -```js | | 14 | +{% initial %} | 17 | 15 | var array = [1, 1, 2, 3, 5, 8]; | 18 | 16 | var l = array.length; | 19 | | -var a = | 20 | | -``` | 21 | | - | 22 | | -```js | | 17 | +var a = | | 18 | +{% solution %} | 23 | 19 | var array = [1, 1, 2, 3, 5, 8]; | 24 | 20 | var l = array.length; | 25 | 21 | var a = 6; | 26 | | -``` | 27 | | - | 28 | | -```js | 29 | | -assert (a === 6) | 30 | | -``` | 31 | | ---- | | 22 | +{% validation %} | | 23 | +assert (a === 6) | | 24 | +{% endexercise %} |
Collapse file Copy file name to clipboardExpand all lines: en/basics/types.md +4-16Lines changed: 4 additions & 16 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -22,22 +22,10 @@ The most common types are: | 22 | 22 |
| 23 | 23 | JavaScript is a *“loosely typed”* language, which means that you don't have to explicitly declare what type of data the variables are. You just need to use the ```var``` keyword to indicate that you are declaring a variable, and the interpreter will work out what data type you are using from the context, and use of quotes. | 24 | 24 |
| 25 | | - | 26 | | - | 27 | | ---- | 28 | | - | | 25 | +{% exercise %} | 29 | 26 | Create a variable named `a` using the keyword `var`. | 30 | | - | 31 | | -```js | 32 | | - | 33 | | -``` | 34 | | - | 35 | | -```js | | 27 | +{% solution %} | 36 | 28 | var a; | 37 | | -``` | 38 | | - | 39 | | -```js | | 29 | +{% validation %} | 40 | 30 | a; | 41 | | -``` | 42 | | - | 43 | | ---- | | 31 | +{% endexercise %} |
Collapse file Copy file name to clipboardExpand all lines: en/conditional/comparators.md +9-16Lines changed: 9 additions & 16 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -20,35 +20,28 @@ Other conditional test: | 20 | 20 | * ```x```: does x exist? | 21 | 21 |
| 22 | 22 |
| 23 | | ---- | 24 | | - | | 23 | +{% exercise %} | 25 | 24 | Add a condition to change the value of `a` to the number 10 if `x` is bigger than 5. | 26 | | - | 27 | | -```js | | 25 | +{% initial %} | 28 | 26 | var x = 6; | 29 | 27 | var a = 0; | 30 | | - | 31 | | - | 32 | | -``` | 33 | | - | 34 | | -```js | | 28 | +{% solution %} | 35 | 29 | var x = 6; | 36 | 30 | var a = 0; | 37 | 31 |
| 38 | 32 | if (x > 5) { | 39 | 33 | a = 10; | 40 | 34 | } | 41 | | -``` | 42 | | - | 43 | | -```js | | 35 | +{% validation %} | 44 | 36 | assert(a === 10); | 45 | | -``` | | 37 | +{% endexercise %} | 46 | 38 |
| 47 | | ---- | 48 | 39 | ##Logical Comparison | 49 | | - In order to avoid the if-else hassle, simple logical comparisons can be utilised. | 50 | | - | | 40 | + | | 41 | +In order to avoid the if-else hassle, simple logical comparisons can be utilised. | | 42 | + | 51 | 43 | ```js | 52 | 44 | var topper = (marks > 85) ? "YES" : "NO"; | 53 | 45 | ``` | | 46 | + | 54 | 47 | In the above example, `?` is a logical operator. The code says that if the value of marks is greater than 85 i.e. `marks > 85` , then `topper = YES` ; otherwise `topper = NO` . Basically, if the comparison condition proves true, the first argument is accessed and if the comparison condition is false , the second argument is accessed. |
Collapse file Copy file name to clipboardExpand all lines: en/conditional/concatenate.md +5-13Lines changed: 5 additions & 13 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -22,11 +22,9 @@ if(country === 'England' || country === 'Germany') { | 22 | 22 |
| 23 | 23 | **Note**: Just like operations on numbers, Condtions can be grouped using parenthesis, ex: ```if ( (name === "John" || name === "Jennifer") && country === "France")```. | 24 | 24 |
| 25 | | ---- | 26 | | - | | 25 | +{% exercise %} | 27 | 26 | Fill up the 2 conditions so that `primaryCategory` equals `"E/J"` only if name equals `"John"` and country is `"England"`, and so that `secondaryCategory` equals `"E|J"` only if name equals `"John"` or country is `"England"` | 28 | | - | 29 | | -```js | | 27 | +{% initial %} | 30 | 28 | var name = "John"; | 31 | 29 | var country = "England"; | 32 | 30 | var primaryCategory, secondaryCategory; | @@ -37,9 +35,7 @@ if ( /* Fill here */ ) { | 37 | 35 | if ( /* Fill here */ ) { | 38 | 36 | secondaryCategory = "E|J"; | 39 | 37 | } | 40 | | -``` | 41 | | - | 42 | | -```js | | 38 | +{% solution %} | 43 | 39 | var name = "John"; | 44 | 40 | var country = "England"; | 45 | 41 | var primaryCategory, secondaryCategory; | @@ -50,10 +46,6 @@ if (name === "John" && country === "England") { | 50 | 46 | if (name === "John" || country === "England") { | 51 | 47 | secondaryCategory = "E|J"; | 52 | 48 | } | 53 | | -``` | 54 | | - | 55 | | -```js | | 49 | +{% validation %} | 56 | 50 | assert(primaryCategory === "E/J" && secondaryCategory === "E|J"); | 57 | | -``` | 58 | | - | 59 | | ---- | | 51 | +{% endexercise %} |
Collapse file Copy file name to clipboardExpand all lines: en/conditional/else.md +5-13Lines changed: 5 additions & 13 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -25,32 +25,24 @@ if(country === 'England') { | 25 | 25 | ``` | 26 | 26 |
| 27 | 27 |
| 28 | | ---- | 29 | | - | | 28 | +{% exercise %} | 30 | 29 | Fill up the value of `name` to validate the `else` condition. | 31 | | - | 32 | | -```js | | 30 | +{% initial %} | 33 | 31 | var name = | 34 | 32 |
| 35 | 33 | if (name === "John") { | 36 | 34 |
| 37 | 35 | } else if (name === "Aaron") { | 38 | 36 | // Valid this condition | 39 | 37 | } | 40 | | -``` | 41 | | - | 42 | | -```js | | 38 | +{% solution %} | 43 | 39 | var name = "Aaron"; | 44 | 40 |
| 45 | 41 | if (name === "John") { | 46 | 42 |
| 47 | 43 | } else if (name === "Aaron") { | 48 | 44 | // Valid this condition | 49 | 45 | } | 50 | | -``` | 51 | | - | 52 | | -```js | | 46 | +{% validation %} | 53 | 47 | assert(name === "Aaron"); | 54 | | -``` | 55 | | - | 56 | | ---- | | 48 | +{% endexercise %} |
Collapse file Copy file name to clipboardExpand all lines: en/conditional/if.md +5-13Lines changed: 5 additions & 13 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -33,28 +33,20 @@ var message = 'this is ' + country + ', the weather is ' + | 33 | 33 |
| 34 | 34 | **Note:** Conditions can also be nested. | 35 | 35 |
| 36 | | ---- | 37 | | - | | 36 | +{% exercise %} | 38 | 37 | Fill up the value of `name` to validate the condition. | 39 | | - | 40 | | -```js | | 38 | +{% initial %} | 41 | 39 | var name = | 42 | 40 |
| 43 | 41 | if (name === "John") { | 44 | 42 |
| 45 | 43 | } | 46 | | -``` | 47 | | - | 48 | | -```js | | 44 | +{% solution %} | 49 | 45 | var name = "John"; | 50 | 46 |
| 51 | 47 | if (name === "John") { | 52 | 48 |
| 53 | 49 | } | 54 | | -``` | 55 | | - | 56 | | -```js | | 50 | +{% validation %} | 57 | 51 | assert(name === "John"); | 58 | | -``` | 59 | | - | 60 | | ---- | | 52 | +{% endexercise %} |
Collapse file Copy file name to clipboardExpand all lines: en/functions/declare.md +5-16Lines changed: 5 additions & 16 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -18,27 +18,16 @@ var double = function(x) { | 18 | 18 | }; | 19 | 19 | ``` | 20 | 20 |
| 21 | | ->*Note:* the function above **may not** be referenced before it is defined, just like any other variable. | 22 | | -
| 23 | | ---- | | 21 | +>*Note:* the function above **may not** be referenced before it is defined, just like any other variable. | 24 | 22 |
| | 23 | +{% exercise %} | 25 | 24 | Declare a function named `triple` that takes an argument and returns its triple. | 26 | | - | 27 | | -```js | 28 | | - | 29 | | -``` | 30 | | - | 31 | | -```js | | 25 | +{% solution %} | 32 | 26 | var triple = function(x) { | 33 | 27 | return x * 3; | 34 | 28 | } | 35 | | -``` | 36 | | - | 37 | | -```js | | 29 | +{% validation %} | 38 | 30 | assert(triple); | 39 | 31 | assert(triple(4) === 12); | 40 | 32 | assert(triple(10) === 30); | 41 | | -``` | 42 | | - | 43 | | ---- | 44 | | - | | 33 | +{% endexercise %} |
Collapse file Copy file name to clipboardExpand all lines: en/functions/higher_order.md +5-13Lines changed: 5 additions & 13 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -88,11 +88,9 @@ double(3); // => 6 | 88 | 88 | triple(3); // => 9 | 89 | 89 | ``` | 90 | 90 |
| 91 | | ---- | 92 | | - | | 91 | +{% exercise %} | 93 | 92 | Define a function named `negate` that takes `add1` as argument and returns a function, that returns the negation of the value returned by `add1`. (Things get a bit more complicated ;) ) | 94 | | - | 95 | | -```js | | 93 | +{% initial %} | 96 | 94 | var add1 = function (x) { | 97 | 95 | return x + 1; | 98 | 96 | }; | @@ -105,9 +103,7 @@ var negate = function(func) { | 105 | 103 | // Because (5+1) * -1 = -6 | 106 | 104 | negate(add1)(5); | 107 | 105 |
| 108 | | -``` | 109 | | - | 110 | | -```js | | 106 | +{% solution %} | 111 | 107 | var add1 = function (x) { | 112 | 108 | return x + 1; | 113 | 109 | } | @@ -119,10 +115,6 @@ var negate = function(func) { | 119 | 115 | } | 120 | 116 |
| 121 | 117 | negate(add1)(5); | 122 | | -``` | 123 | | - | 124 | | -```js | | 118 | +{% validation %} | 125 | 119 | assert(negate(add1)(5) === -6); | 126 | | -``` | 127 | | - | 128 | | ---- | | 120 | +{% endexercise %} |
|