diff --git a/LANGS.md b/LANGS.md new file mode 100644 index 00000000..3fbfcc02 --- /dev/null +++ b/LANGS.md @@ -0,0 +1,3 @@ +# Language + +* [English](./en) diff --git a/README.md b/README.md index e793d266..42f29219 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,9 @@ Learn Javascript This book will teach you the basics of programming and Javascript. Whether you are an experienced programmer or not, this book is intended for everyone who wishes to learn the JavaScript programming language. -![Screen](./assets/intro.png) +This book has been generated using [GitBook](http://www.gitbook.com) and is open source, feel free to contribute or signal issues on [GitHub](https://github.com/GitbookIO/javascript). You can download a **PDF** or **ePUB** version at [https://www.gitbook.com/book/GitBookIO/javascript](https://www.gitbook.com/book/GitBookIO/javascript). + +![Screen](./en/assets/intro.png) -JavaScript (*JS for short*) is the programming language that enables web pages to respond to user interaction beyond the basic level. It was created in 1995, and is today one of the most famous and used programming languages. -**Note:** This book has been generated using [GitBook](http://www.gitbook.io) and is open source, feel free to contribute or signal issues on [GitHub](https://github.com/GitbookIO/javascript). You can download a **PDF** or **ePUB** version at [https://www.gitbook.io/book/GitBookIO/javascript](https://www.gitbook.io/book/GitBookIO/javascript). diff --git a/book.json b/book.json index c43f326c..5756364a 100644 --- a/book.json +++ b/book.json @@ -1,4 +1,5 @@ { + "gitbook": ">1.x.x", "plugins": [ "exercises" ] diff --git a/en/README.md b/en/README.md new file mode 100644 index 00000000..7ec588c8 --- /dev/null +++ b/en/README.md @@ -0,0 +1,8 @@ +Learn Javascript +====== + +This book will teach you the basics of programming and Javascript. Whether you are an experienced programmer or not, this book is intended for everyone who wishes to learn the JavaScript programming language. + +![Screen](./assets/intro.png) + +JavaScript (*JS for short*) is the programming language that enables web pages to respond to user interaction beyond the basic level. It was created in 1995, and is today one of the most famous and used programming languages. diff --git a/SUMMARY.md b/en/SUMMARY.md similarity index 100% rename from SUMMARY.md rename to en/SUMMARY.md diff --git a/arrays/README.md b/en/arrays/README.md similarity index 99% rename from arrays/README.md rename to en/arrays/README.md index 9d659cfa..0690816e 100644 --- a/arrays/README.md +++ b/en/arrays/README.md @@ -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]; diff --git a/arrays/indices.md b/en/arrays/indices.md similarity index 93% rename from arrays/indices.md rename to en/arrays/indices.md index 0d72fbb4..cddbbb7f 100644 --- a/arrays/indices.md +++ b/en/arrays/indices.md @@ -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 %} diff --git a/arrays/length.md b/en/arrays/length.md similarity index 79% rename from arrays/length.md rename to en/arrays/length.md index e4bd021e..78deb9f4 100644 --- a/arrays/length.md +++ b/en/arrays/length.md @@ -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) -``` ---- \ No newline at end of file +{% validation %} +assert (a === 6) +{% endexercise %} diff --git a/assets/intro.png b/en/assets/intro.png similarity index 100% rename from assets/intro.png rename to en/assets/intro.png diff --git a/basics/README.md b/en/basics/README.md similarity index 100% rename from basics/README.md rename to en/basics/README.md diff --git a/basics/comments.md b/en/basics/comments.md similarity index 100% rename from basics/comments.md rename to en/basics/comments.md diff --git a/basics/equality.md b/en/basics/equality.md similarity index 100% rename from basics/equality.md rename to en/basics/equality.md diff --git a/basics/types.md b/en/basics/types.md similarity index 95% rename from basics/types.md rename to en/basics/types.md index 82d2f8f3..cd0c65f7 100644 --- a/basics/types.md +++ b/en/basics/types.md @@ -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 %} diff --git a/basics/variables.md b/en/basics/variables.md similarity index 100% rename from basics/variables.md rename to en/basics/variables.md diff --git a/conditional/README.md b/en/conditional/README.md similarity index 100% rename from conditional/README.md rename to en/conditional/README.md diff --git a/conditional/comparators.md b/en/conditional/comparators.md similarity index 90% rename from conditional/comparators.md rename to en/conditional/comparators.md index adf2e95e..3cc21648 100644 --- a/conditional/comparators.md +++ b/en/conditional/comparators.md @@ -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. diff --git a/conditional/concatenate.md b/en/conditional/concatenate.md similarity index 94% rename from conditional/concatenate.md rename to en/conditional/concatenate.md index b5f4d939..d31b0565 100644 --- a/conditional/concatenate.md +++ b/en/conditional/concatenate.md @@ -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; @@ -37,9 +35,7 @@ if ( /* Fill here */ ) { if ( /* Fill here */ ) { secondaryCategory = "E|J"; } -``` - -```js +{% solution %} var name = "John"; var country = "England"; var primaryCategory, secondaryCategory; @@ -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 %} diff --git a/conditional/else.md b/en/conditional/else.md similarity index 91% rename from conditional/else.md rename to en/conditional/else.md index de0f9401..e667ddb7 100644 --- a/conditional/else.md +++ b/en/conditional/else.md @@ -25,11 +25,9 @@ if(country === 'England') { ``` ---- - +{% exercise %} Fill up the value of `name` to validate the `else` condition. - -```js +{% initial %} var name = if (name === "John") { @@ -37,9 +35,7 @@ if (name === "John") { } else if (name === "Aaron") { // Valid this condition } -``` - -```js +{% solution %} var name = "Aaron"; if (name === "John") { @@ -47,10 +43,6 @@ if (name === "John") { } else if (name === "Aaron") { // Valid this condition } -``` - -```js +{% validation %} assert(name === "Aaron"); -``` - ---- +{% endexercise %} diff --git a/conditional/if.md b/en/conditional/if.md similarity index 93% rename from conditional/if.md rename to en/conditional/if.md index 83d6c780..b9692db4 100644 --- a/conditional/if.md +++ b/en/conditional/if.md @@ -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 %} diff --git a/cover.jpg b/en/cover.jpg similarity index 100% rename from cover.jpg rename to en/cover.jpg diff --git a/cover_small.jpg b/en/cover_small.jpg similarity index 100% rename from cover_small.jpg rename to en/cover_small.jpg diff --git a/functions/README.md b/en/functions/README.md similarity index 100% rename from functions/README.md rename to en/functions/README.md diff --git a/functions/declare.md b/en/functions/declare.md similarity index 88% rename from functions/declare.md rename to en/functions/declare.md index 0767a73c..cf4e8b31 100644 --- a/functions/declare.md +++ b/en/functions/declare.md @@ -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 %} diff --git a/functions/higher_order.md b/en/functions/higher_order.md similarity index 97% rename from functions/higher_order.md rename to en/functions/higher_order.md index 49183757..66984ad9 100644 --- a/functions/higher_order.md +++ b/en/functions/higher_order.md @@ -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; }; @@ -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; } @@ -119,10 +115,6 @@ var negate = function(func) { } negate(add1)(5); -``` - -```js +{% validation %} assert(negate(add1)(5) === -6); -``` - ---- +{% endexercise %} diff --git a/loops/README.md b/en/loops/README.md similarity index 100% rename from loops/README.md rename to en/loops/README.md diff --git a/loops/for.md b/en/loops/for.md similarity index 90% rename from loops/for.md rename to en/loops/for.md index 8b4487d5..4dbd89e7 100644 --- a/loops/for.md +++ b/en/loops/for.md @@ -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 %} diff --git a/loops/while.md b/en/loops/while.md similarity index 93% rename from loops/while.md rename to en/loops/while.md index 8d6db0aa..bcc3ffb0 100644 --- a/loops/while.md +++ b/en/loops/while.md @@ -30,15 +30,11 @@ do { **Note**: Be careful to avoid infinite looping if the condition is always true! ---- - +{% exercise %} Using a while-loop, create a variable named `message` that equals the concatenation of integers (0, 1, 2, ...) as long as its length (`message.length`) is less than 100. - -```js +{% initial %} var message = ""; -``` - -```js +{% solution %} var message = ""; var i = 0; @@ -46,9 +42,7 @@ while (message.length < 100) { message = message + i; i = i + 1; } -``` - -```js +{% validation %} var message2 = ""; var i2 = 0; @@ -57,6 +51,4 @@ while (message2.length < 100) { i2 = i2 + 1; } assert(message === message2); -``` - ---- +{% endexercise %} diff --git a/numbers/README.md b/en/numbers/README.md similarity index 100% rename from numbers/README.md rename to en/numbers/README.md diff --git a/numbers/advanced.md b/en/numbers/advanced.md similarity index 86% rename from numbers/advanced.md rename to en/numbers/advanced.md index d8042818..12cad0e7 100644 --- a/numbers/advanced.md +++ b/en/numbers/advanced.md @@ -12,24 +12,16 @@ Some advanced operators can be used, such as: ---- - +{% exercise %} Define a variable `c` as the modulus of the decremented value of `x` by 3. - -```js +{% initial %} var x = 10; var c = -``` - -```js +{% solution %} var x = 10; var c = (--x) % 3; -``` - -```js +{% validation %} assert(c === 0); -``` - ---- +{% endexercise %} diff --git a/numbers/create.md b/en/numbers/create.md similarity index 85% rename from numbers/create.md rename to en/numbers/create.md index c4b62e3f..e5bfae69 100644 --- a/numbers/create.md +++ b/en/numbers/create.md @@ -19,24 +19,15 @@ var a = 2; var b = a; ``` - ---- - +{% exercise %} Create a variable `x` which equals `10` and create a variable `y` which equals `a`. - -```js +{% initial %} var a = 11; -``` - -```js +{% solution %} var a = 11; var x = 10; var y = a; -``` - -```js +{% validation %} assert(x === 10 && y === a); -``` - ---- +{% endexercise %} diff --git a/numbers/operators.md b/en/numbers/operators.md similarity index 88% rename from numbers/operators.md rename to en/numbers/operators.md index 51f4e500..e6202271 100644 --- a/numbers/operators.md +++ b/en/numbers/operators.md @@ -10,30 +10,22 @@ You can apply mathematic operations to numbers using some basic operators like: You can use parentheses just like in math to separate and group expressions: ```c = (a / b) + d``` ---- - +{% exercise %} Create a variable `x` equal to the sum of `a` and `b` divided by `c` and finally multiplied by `d`. - -```js +{% initial %} var a = 2034547; var b = 1.567; var c = 6758.768; var d = 45084; var x = -``` - -```js +{% solution %} var a = 2034547; var b = 1.567; var c = 6758.768; var d = 45084; var x = ((a + b) / c) * d; -``` - -```js +{% validation %} assert(x === (((a + b) / c) * d)); -``` - ---- +{% endexercise %} diff --git a/objects/README.md b/en/objects/README.md similarity index 100% rename from objects/README.md rename to en/objects/README.md diff --git a/objects/creation.md b/en/objects/creation.md similarity index 100% rename from objects/creation.md rename to en/objects/creation.md diff --git a/objects/delete.md b/en/objects/delete.md similarity index 100% rename from objects/delete.md rename to en/objects/delete.md diff --git a/objects/enumeration.md b/en/objects/enumeration.md similarity index 100% rename from objects/enumeration.md rename to en/objects/enumeration.md diff --git a/objects/global_footprint.md b/en/objects/global_footprint.md similarity index 100% rename from objects/global_footprint.md rename to en/objects/global_footprint.md diff --git a/objects/mutable.md b/en/objects/mutable.md similarity index 100% rename from objects/mutable.md rename to en/objects/mutable.md diff --git a/objects/properties.md b/en/objects/properties.md similarity index 100% rename from objects/properties.md rename to en/objects/properties.md diff --git a/objects/prototype.md b/en/objects/prototype.md similarity index 100% rename from objects/prototype.md rename to en/objects/prototype.md diff --git a/objects/reference.md b/en/objects/reference.md similarity index 100% rename from objects/reference.md rename to en/objects/reference.md diff --git a/strings/README.md b/en/strings/README.md similarity index 100% rename from strings/README.md rename to en/strings/README.md diff --git a/strings/concat.md b/en/strings/concat.md similarity index 87% rename from strings/concat.md rename to en/strings/concat.md index 84ddd5b3..81c7a122 100644 --- a/strings/concat.md +++ b/en/strings/concat.md @@ -6,26 +6,18 @@ Concatenation involves adding two or more strings together, creating a larger st var bigStr = 'Hi ' + 'JS strings are nice ' + 'and ' + 'easy to add'; ``` ---- - +{% exercise %} Add up the different names so that the `fullName` variable contains John's complete name. - -```js +{% initial %} var firstName = "John"; var lastName = "Smith"; var fullName = -``` - -```js +{% solution %} var firstName = "John"; var lastName = "Smith"; var fullName = firstName + " " + lastName; -``` - -```js +{% validation %} assert(fullName === 'John Smith'); -``` - ---- +{% endexercise %} diff --git a/strings/create.md b/en/strings/create.md similarity index 90% rename from strings/create.md rename to en/strings/create.md index e303337e..79e07fcf 100644 --- a/strings/create.md +++ b/en/strings/create.md @@ -19,20 +19,10 @@ In Javascript, Strings can contain UTF-8 characters: **Note:** Strings can not be subtracted, multiplied or divided. ---- - +{% exercise %} Create a variable named `str` set to the value `"abc"`. - -```js - -``` - -```js +{% solution %} var str = 'abc'; -``` - -```js +{% validation %} assert(str === 'abc'); -``` - ---- +{% endexercise %} diff --git a/strings/length.md b/en/strings/length.md similarity index 84% rename from strings/length.md rename to en/strings/length.md index 93554813..b9932177 100644 --- a/strings/length.md +++ b/en/strings/length.md @@ -10,24 +10,16 @@ var size = 'Our lovely string'.length; **Note:** Strings can not be substracted, multiplied or divided. ---- - +{% exercise %} Store in the variable named `size` the length of `str`. - -```js +{% initial %} var str = "Hello World"; var size = -``` - -```js +{% solution %} var str = "Hello World"; var size = str.length; -``` - -```js +{% validation %} assert(size === str.length); -``` - ---- +{% endexercise %} \ No newline at end of file diff --git a/strings/substrings.md b/en/strings/substrings.md similarity index 75% rename from strings/substrings.md rename to en/strings/substrings.md index 6346187e..998c48a5 100644 --- a/strings/substrings.md +++ b/en/strings/substrings.md @@ -1,7 +1,7 @@ -#Substrings +# Substrings -substring is used to take a part of a string. -Syntax: substring(first_index,last_index). +substring is used to take a part of a string. +Syntax: substring(first_index,last_index). ```js var a = 'Hello world!'; @@ -18,8 +18,8 @@ This gives the whole string from the character with index 2. ``` 'llo world!'``` ##substr -There is also a method substr() that works slightly differently. Instead of the second number being an index number, -it gives the number of characters. +There is also a method substr() that works slightly differently. Instead of the second number being an index number, +it gives the number of characters. ```js var a = 'Hello world!'; document.write(a.substr(1,6));