Skip to content

Commit 8a8361f

Browse files
committed
Convert exercises to use blocks
1 parent c41a558 commit 8a8361f

File tree

19 files changed

+95
-237
lines changed

19 files changed

+95
-237
lines changed

en/arrays/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Arrays are a fundamental part of programming. An array is a list of data. We can
55
The data in arrays are called **elements**.
66

77
Here is a simple array:
8+
89
```javascript
910
// 1, 1, 2, 3, 5, and 8 are the elements in this array
1011
var numbers = [1, 1, 2, 3, 5, 8];

en/arrays/indices.md

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,24 @@ var fruits = ["apple", "banana", "pineapple", "strawberry"];
1111
// second element. Result: banana = "banana"
1212
var banana = fruits[1];
1313
```
14-
---
1514

15+
{% exercise %}
1616
Define the variables using the indices of the array
17-
18-
```js
17+
{% initial %}
1918
var cars = ["Mazda", "Honda", "Chevy", "Ford"]
2019
var honda =
2120
var ford =
2221
var chevy =
2322
var mazda =
24-
```
25-
26-
```js
23+
{% solution %}
2724
var cars = ["Mazda", "Honda", "Chevy", "Ford"]
2825
var honda = cars[1];
2926
var ford = cars[3];
3027
var chevy = cars[2];
3128
var mazda = cars[0];
32-
```
33-
34-
```js
29+
{% validation %}
3530
assert(honda === "Honda");
3631
assert(ford === "Ford");
3732
assert(chevy === "Chevy");
3833
assert(mazda === "Mazda");
39-
```
40-
41-
---
34+
{% endexercise %}

en/arrays/length.md

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,16 @@ var array = [1 , 2, 3];
99
var l = array.length;
1010
```
1111

12-
---
13-
12+
{% exercise %}
1413
Define the variable a to be the number value of the length of the array
15-
16-
```js
14+
{% initial %}
1715
var array = [1, 1, 2, 3, 5, 8];
1816
var l = array.length;
19-
var a =
20-
```
21-
22-
```js
17+
var a =
18+
{% solution %}
2319
var array = [1, 1, 2, 3, 5, 8];
2420
var l = array.length;
2521
var a = 6;
26-
```
27-
28-
```js
29-
assert (a === 6)
30-
```
31-
---
22+
{% validation %}
23+
assert (a === 6)
24+
{% endexercise %}

en/basics/types.md

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,10 @@ The most common types are:
2222

2323
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.
2424

25-
26-
27-
---
28-
25+
{% exercise %}
2926
Create a variable named `a` using the keyword `var`.
30-
31-
```js
32-
33-
```
34-
35-
```js
27+
{% solution %}
3628
var a;
37-
```
38-
39-
```js
29+
{% validation %}
4030
a;
41-
```
42-
43-
---
31+
{% endexercise %}

en/conditional/comparators.md

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,28 @@ Other conditional test:
2020
* ```x```: does x exist?
2121

2222

23-
---
24-
23+
{% exercise %}
2524
Add a condition to change the value of `a` to the number 10 if `x` is bigger than 5.
26-
27-
```js
25+
{% initial %}
2826
var x = 6;
2927
var a = 0;
30-
31-
32-
```
33-
34-
```js
28+
{% solution %}
3529
var x = 6;
3630
var a = 0;
3731

3832
if (x > 5) {
3933
a = 10;
4034
}
41-
```
42-
43-
```js
35+
{% validation %}
4436
assert(a === 10);
45-
```
37+
{% endexercise %}
4638

47-
---
4839
##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+
5143
```js
5244
var topper = (marks > 85) ? "YES" : "NO";
5345
```
46+
5447
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.

en/conditional/concatenate.md

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@ if(country === 'England' || country === 'Germany') {
2222

2323
**Note**: Just like operations on numbers, Condtions can be grouped using parenthesis, ex: ```if ( (name === "John" || name === "Jennifer") && country === "France")```.
2424

25-
---
26-
25+
{% exercise %}
2726
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 %}
3028
var name = "John";
3129
var country = "England";
3230
var primaryCategory, secondaryCategory;
@@ -37,9 +35,7 @@ if ( /* Fill here */ ) {
3735
if ( /* Fill here */ ) {
3836
secondaryCategory = "E|J";
3937
}
40-
```
41-
42-
```js
38+
{% solution %}
4339
var name = "John";
4440
var country = "England";
4541
var primaryCategory, secondaryCategory;
@@ -50,10 +46,6 @@ if (name === "John" && country === "England") {
5046
if (name === "John" || country === "England") {
5147
secondaryCategory = "E|J";
5248
}
53-
```
54-
55-
```js
49+
{% validation %}
5650
assert(primaryCategory === "E/J" && secondaryCategory === "E|J");
57-
```
58-
59-
---
51+
{% endexercise %}

en/conditional/else.md

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,32 +25,24 @@ if(country === 'England') {
2525
```
2626

2727

28-
---
29-
28+
{% exercise %}
3029
Fill up the value of `name` to validate the `else` condition.
31-
32-
```js
30+
{% initial %}
3331
var name =
3432

3533
if (name === "John") {
3634

3735
} else if (name === "Aaron") {
3836
// Valid this condition
3937
}
40-
```
41-
42-
```js
38+
{% solution %}
4339
var name = "Aaron";
4440

4541
if (name === "John") {
4642

4743
} else if (name === "Aaron") {
4844
// Valid this condition
4945
}
50-
```
51-
52-
```js
46+
{% validation %}
5347
assert(name === "Aaron");
54-
```
55-
56-
---
48+
{% endexercise %}

en/conditional/if.md

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,20 @@ var message = 'this is ' + country + ', the weather is ' +
3333

3434
**Note:** Conditions can also be nested.
3535

36-
---
37-
36+
{% exercise %}
3837
Fill up the value of `name` to validate the condition.
39-
40-
```js
38+
{% initial %}
4139
var name =
4240

4341
if (name === "John") {
4442

4543
}
46-
```
47-
48-
```js
44+
{% solution %}
4945
var name = "John";
5046

5147
if (name === "John") {
5248

5349
}
54-
```
55-
56-
```js
50+
{% validation %}
5751
assert(name === "John");
58-
```
59-
60-
---
52+
{% endexercise %}

en/functions/declare.md

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,16 @@ var double = function(x) {
1818
};
1919
```
2020

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.
2422
23+
{% exercise %}
2524
Declare a function named `triple` that takes an argument and returns its triple.
26-
27-
```js
28-
29-
```
30-
31-
```js
25+
{% solution %}
3226
var triple = function(x) {
3327
return x * 3;
3428
}
35-
```
36-
37-
```js
29+
{% validation %}
3830
assert(triple);
3931
assert(triple(4) === 12);
4032
assert(triple(10) === 30);
41-
```
42-
43-
---
44-
33+
{% endexercise %}

en/functions/higher_order.md

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,9 @@ double(3); // => 6
8888
triple(3); // => 9
8989
```
9090

91-
---
92-
91+
{% exercise %}
9392
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 %}
9694
var add1 = function (x) {
9795
return x + 1;
9896
};
@@ -105,9 +103,7 @@ var negate = function(func) {
105103
// Because (5+1) * -1 = -6
106104
negate(add1)(5);
107105

108-
```
109-
110-
```js
106+
{% solution %}
111107
var add1 = function (x) {
112108
return x + 1;
113109
}
@@ -119,10 +115,6 @@ var negate = function(func) {
119115
}
120116

121117
negate(add1)(5);
122-
```
123-
124-
```js
118+
{% validation %}
125119
assert(negate(add1)(5) === -6);
126-
```
127-
128-
---
120+
{% endexercise %}

0 commit comments

Comments
 (0)