Skip to content

Commit

Permalink
Convert exercises to use blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
SamyPesse committed Feb 14, 2015
1 parent c41a558 commit 8a8361f
Show file tree
Hide file tree
Showing 19 changed files with 95 additions and 237 deletions.
1 change: 1 addition & 0 deletions en/arrays/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Arrays are a fundamental part of programming. An array is a list of data. We can
The data in arrays are called **elements**.

Here is a simple array:

```javascript
// 1, 1, 2, 3, 5, and 8 are the elements in this array
var numbers = [1, 1, 2, 3, 5, 8];
Expand Down
17 changes: 5 additions & 12 deletions en/arrays/indices.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,24 @@ var fruits = ["apple", "banana", "pineapple", "strawberry"];
// second element. Result: banana = "banana"
var banana = fruits[1];
```
---

{% exercise %}
Define the variables using the indices of the array

```js
{% initial %}
var cars = ["Mazda", "Honda", "Chevy", "Ford"]
var honda =
var ford =
var chevy =
var mazda =
```

```js
{% solution %}
var cars = ["Mazda", "Honda", "Chevy", "Ford"]
var honda = cars[1];
var ford = cars[3];
var chevy = cars[2];
var mazda = cars[0];
```

```js
{% validation %}
assert(honda === "Honda");
assert(ford === "Ford");
assert(chevy === "Chevy");
assert(mazda === "Mazda");
```

---
{% endexercise %}
21 changes: 7 additions & 14 deletions en/arrays/length.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,16 @@ var array = [1 , 2, 3];
var l = array.length;
```

---

{% exercise %}
Define the variable a to be the number value of the length of the array

```js
{% initial %}
var array = [1, 1, 2, 3, 5, 8];
var l = array.length;
var a =
```

```js
var a =
{% solution %}
var array = [1, 1, 2, 3, 5, 8];
var l = array.length;
var a = 6;
```

```js
assert (a === 6)
```
---
{% validation %}
assert (a === 6)
{% endexercise %}
20 changes: 4 additions & 16 deletions en/basics/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,10 @@ The most common types are:

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.



---

{% exercise %}
Create a variable named `a` using the keyword `var`.

```js

```

```js
{% solution %}
var a;
```

```js
{% validation %}
a;
```

---
{% endexercise %}
25 changes: 9 additions & 16 deletions en/conditional/comparators.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,28 @@ Other conditional test:
* ```x```: does x exist?


---

{% exercise %}
Add a condition to change the value of `a` to the number 10 if `x` is bigger than 5.

```js
{% initial %}
var x = 6;
var a = 0;


```

```js
{% solution %}
var x = 6;
var a = 0;

if (x > 5) {
a = 10;
}
```

```js
{% validation %}
assert(a === 10);
```
{% endexercise %}

---
##Logical Comparison
In order to avoid the if-else hassle, simple logical comparisons can be utilised.


In order to avoid the if-else hassle, simple logical comparisons can be utilised.

```js
var topper = (marks > 85) ? "YES" : "NO";
```

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.
18 changes: 5 additions & 13 deletions en/conditional/concatenate.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ if(country === 'England' || country === 'Germany') {

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

---

{% exercise %}
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"`

```js
{% initial %}
var name = "John";
var country = "England";
var primaryCategory, secondaryCategory;
Expand All @@ -37,9 +35,7 @@ if ( /* Fill here */ ) {
if ( /* Fill here */ ) {
secondaryCategory = "E|J";
}
```

```js
{% solution %}
var name = "John";
var country = "England";
var primaryCategory, secondaryCategory;
Expand All @@ -50,10 +46,6 @@ if (name === "John" && country === "England") {
if (name === "John" || country === "England") {
secondaryCategory = "E|J";
}
```

```js
{% validation %}
assert(primaryCategory === "E/J" && secondaryCategory === "E|J");
```

---
{% endexercise %}
18 changes: 5 additions & 13 deletions en/conditional/else.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,24 @@ if(country === 'England') {
```


---

{% exercise %}
Fill up the value of `name` to validate the `else` condition.

```js
{% initial %}
var name =

if (name === "John") {

} else if (name === "Aaron") {
// Valid this condition
}
```

```js
{% solution %}
var name = "Aaron";

if (name === "John") {

} else if (name === "Aaron") {
// Valid this condition
}
```

```js
{% validation %}
assert(name === "Aaron");
```

---
{% endexercise %}
18 changes: 5 additions & 13 deletions en/conditional/if.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,20 @@ var message = 'this is ' + country + ', the weather is ' +

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

---

{% exercise %}
Fill up the value of `name` to validate the condition.

```js
{% initial %}
var name =

if (name === "John") {

}
```

```js
{% solution %}
var name = "John";

if (name === "John") {

}
```

```js
{% validation %}
assert(name === "John");
```

---
{% endexercise %}
21 changes: 5 additions & 16 deletions en/functions/declare.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,16 @@ var double = function(x) {
};
```

>*Note:* the function above **may not** be referenced before it is defined, just like any other variable.
---
>*Note:* the function above **may not** be referenced before it is defined, just like any other variable.
{% exercise %}
Declare a function named `triple` that takes an argument and returns its triple.

```js

```

```js
{% solution %}
var triple = function(x) {
return x * 3;
}
```

```js
{% validation %}
assert(triple);
assert(triple(4) === 12);
assert(triple(10) === 30);
```

---

{% endexercise %}
18 changes: 5 additions & 13 deletions en/functions/higher_order.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,9 @@ double(3); // => 6
triple(3); // => 9
```

---

{% exercise %}
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 ;) )

```js
{% initial %}
var add1 = function (x) {
return x + 1;
};
Expand All @@ -105,9 +103,7 @@ var negate = function(func) {
// Because (5+1) * -1 = -6
negate(add1)(5);

```

```js
{% solution %}
var add1 = function (x) {
return x + 1;
}
Expand All @@ -119,10 +115,6 @@ var negate = function(func) {
}

negate(add1)(5);
```

```js
{% validation %}
assert(negate(add1)(5) === -6);
```

---
{% endexercise %}
18 changes: 5 additions & 13 deletions en/loops/for.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,21 @@ for(var i = 0; i < 10; i = i + 1){
>***Note***: `i = i + 1` can be written `i++`.

---

{% exercise %}
Using a for-loop, create a variable named `message` that equals the concatenation of integers (0, 1, 2, ...) from 0 to 99.

```js
{% initial %}
var message = "";
```

```js
{% solution %}
var message = "";

for(var i = 0; i < 100; i++){
message = message + i;
}
```

```js
{% validation %}
var message2 = ""

for(var i = 0; i < 100; i++){
message2 = message2 + i;
}
assert(message === message2);
```

---
{% endexercise %}
Loading

0 comments on commit 8a8361f

Please sign in to comment.