From c41a558721faf451b8dde39e6cf176e80766d124 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Fri, 13 Feb 2015 17:10:28 +0100 Subject: [PATCH 1/3] Convert to multilingual --- LANGS.md | 3 +++ book.json | 1 + en/README.md | 8 ++++++++ SUMMARY.md => en/SUMMARY.md | 0 {arrays => en/arrays}/README.md | 0 {arrays => en/arrays}/indices.md | 0 {arrays => en/arrays}/length.md | 0 {assets => en/assets}/intro.png | Bin {basics => en/basics}/README.md | 0 {basics => en/basics}/comments.md | 0 {basics => en/basics}/equality.md | 0 {basics => en/basics}/types.md | 0 {basics => en/basics}/variables.md | 0 {conditional => en/conditional}/README.md | 0 {conditional => en/conditional}/comparators.md | 0 {conditional => en/conditional}/concatenate.md | 0 {conditional => en/conditional}/else.md | 0 {conditional => en/conditional}/if.md | 0 cover.jpg => en/cover.jpg | Bin cover_small.jpg => en/cover_small.jpg | Bin {functions => en/functions}/README.md | 0 {functions => en/functions}/declare.md | 0 {functions => en/functions}/higher_order.md | 0 {loops => en/loops}/README.md | 0 {loops => en/loops}/for.md | 0 {loops => en/loops}/while.md | 0 {numbers => en/numbers}/README.md | 0 {numbers => en/numbers}/advanced.md | 0 {numbers => en/numbers}/create.md | 0 {numbers => en/numbers}/operators.md | 0 {objects => en/objects}/README.md | 0 {objects => en/objects}/creation.md | 0 {objects => en/objects}/delete.md | 0 {objects => en/objects}/enumeration.md | 0 {objects => en/objects}/global_footprint.md | 0 {objects => en/objects}/mutable.md | 0 {objects => en/objects}/properties.md | 0 {objects => en/objects}/prototype.md | 0 {objects => en/objects}/reference.md | 0 {strings => en/strings}/README.md | 0 {strings => en/strings}/concat.md | 0 {strings => en/strings}/create.md | 0 {strings => en/strings}/length.md | 0 {strings => en/strings}/substrings.md | 0 44 files changed, 12 insertions(+) create mode 100644 LANGS.md create mode 100644 en/README.md rename SUMMARY.md => en/SUMMARY.md (100%) rename {arrays => en/arrays}/README.md (100%) rename {arrays => en/arrays}/indices.md (100%) rename {arrays => en/arrays}/length.md (100%) rename {assets => en/assets}/intro.png (100%) rename {basics => en/basics}/README.md (100%) rename {basics => en/basics}/comments.md (100%) rename {basics => en/basics}/equality.md (100%) rename {basics => en/basics}/types.md (100%) rename {basics => en/basics}/variables.md (100%) rename {conditional => en/conditional}/README.md (100%) rename {conditional => en/conditional}/comparators.md (100%) rename {conditional => en/conditional}/concatenate.md (100%) rename {conditional => en/conditional}/else.md (100%) rename {conditional => en/conditional}/if.md (100%) rename cover.jpg => en/cover.jpg (100%) rename cover_small.jpg => en/cover_small.jpg (100%) rename {functions => en/functions}/README.md (100%) rename {functions => en/functions}/declare.md (100%) rename {functions => en/functions}/higher_order.md (100%) rename {loops => en/loops}/README.md (100%) rename {loops => en/loops}/for.md (100%) rename {loops => en/loops}/while.md (100%) rename {numbers => en/numbers}/README.md (100%) rename {numbers => en/numbers}/advanced.md (100%) rename {numbers => en/numbers}/create.md (100%) rename {numbers => en/numbers}/operators.md (100%) rename {objects => en/objects}/README.md (100%) rename {objects => en/objects}/creation.md (100%) rename {objects => en/objects}/delete.md (100%) rename {objects => en/objects}/enumeration.md (100%) rename {objects => en/objects}/global_footprint.md (100%) rename {objects => en/objects}/mutable.md (100%) rename {objects => en/objects}/properties.md (100%) rename {objects => en/objects}/prototype.md (100%) rename {objects => en/objects}/reference.md (100%) rename {strings => en/strings}/README.md (100%) rename {strings => en/strings}/concat.md (100%) rename {strings => en/strings}/create.md (100%) rename {strings => en/strings}/length.md (100%) rename {strings => en/strings}/substrings.md (100%) 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/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 100% rename from arrays/README.md rename to en/arrays/README.md diff --git a/arrays/indices.md b/en/arrays/indices.md similarity index 100% rename from arrays/indices.md rename to en/arrays/indices.md diff --git a/arrays/length.md b/en/arrays/length.md similarity index 100% rename from arrays/length.md rename to en/arrays/length.md 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 100% rename from basics/types.md rename to en/basics/types.md 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 100% rename from conditional/comparators.md rename to en/conditional/comparators.md diff --git a/conditional/concatenate.md b/en/conditional/concatenate.md similarity index 100% rename from conditional/concatenate.md rename to en/conditional/concatenate.md diff --git a/conditional/else.md b/en/conditional/else.md similarity index 100% rename from conditional/else.md rename to en/conditional/else.md diff --git a/conditional/if.md b/en/conditional/if.md similarity index 100% rename from conditional/if.md rename to en/conditional/if.md 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 100% rename from functions/declare.md rename to en/functions/declare.md diff --git a/functions/higher_order.md b/en/functions/higher_order.md similarity index 100% rename from functions/higher_order.md rename to en/functions/higher_order.md 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 100% rename from loops/for.md rename to en/loops/for.md diff --git a/loops/while.md b/en/loops/while.md similarity index 100% rename from loops/while.md rename to en/loops/while.md 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 100% rename from numbers/advanced.md rename to en/numbers/advanced.md diff --git a/numbers/create.md b/en/numbers/create.md similarity index 100% rename from numbers/create.md rename to en/numbers/create.md diff --git a/numbers/operators.md b/en/numbers/operators.md similarity index 100% rename from numbers/operators.md rename to en/numbers/operators.md 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 100% rename from strings/concat.md rename to en/strings/concat.md diff --git a/strings/create.md b/en/strings/create.md similarity index 100% rename from strings/create.md rename to en/strings/create.md diff --git a/strings/length.md b/en/strings/length.md similarity index 100% rename from strings/length.md rename to en/strings/length.md diff --git a/strings/substrings.md b/en/strings/substrings.md similarity index 100% rename from strings/substrings.md rename to en/strings/substrings.md From 8a8361f1d337946fff980875f2f2f4d1b05efbaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Sat, 14 Feb 2015 11:34:13 +0100 Subject: [PATCH 2/3] Convert exercises to use blocks --- en/arrays/README.md | 1 + en/arrays/indices.md | 17 +++++------------ en/arrays/length.md | 21 +++++++-------------- en/basics/types.md | 20 ++++---------------- en/conditional/comparators.md | 25 +++++++++---------------- en/conditional/concatenate.md | 18 +++++------------- en/conditional/else.md | 18 +++++------------- en/conditional/if.md | 18 +++++------------- en/functions/declare.md | 21 +++++---------------- en/functions/higher_order.md | 18 +++++------------- en/loops/for.md | 18 +++++------------- en/loops/while.md | 18 +++++------------- en/numbers/advanced.md | 18 +++++------------- en/numbers/create.md | 19 +++++-------------- en/numbers/operators.md | 18 +++++------------- en/strings/concat.md | 18 +++++------------- en/strings/create.md | 18 ++++-------------- en/strings/length.md | 18 +++++------------- en/strings/substrings.md | 10 +++++----- 19 files changed, 95 insertions(+), 237 deletions(-) diff --git a/en/arrays/README.md b/en/arrays/README.md index 9d659cfa..0690816e 100644 --- a/en/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/en/arrays/indices.md b/en/arrays/indices.md index 0d72fbb4..cddbbb7f 100644 --- a/en/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/en/arrays/length.md b/en/arrays/length.md index e4bd021e..78deb9f4 100644 --- a/en/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/en/basics/types.md b/en/basics/types.md index 82d2f8f3..cd0c65f7 100644 --- a/en/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/en/conditional/comparators.md b/en/conditional/comparators.md index adf2e95e..3cc21648 100644 --- a/en/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/en/conditional/concatenate.md b/en/conditional/concatenate.md index b5f4d939..d31b0565 100644 --- a/en/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/en/conditional/else.md b/en/conditional/else.md index de0f9401..e667ddb7 100644 --- a/en/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/en/conditional/if.md b/en/conditional/if.md index 83d6c780..b9692db4 100644 --- a/en/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/en/functions/declare.md b/en/functions/declare.md index 0767a73c..cf4e8b31 100644 --- a/en/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/en/functions/higher_order.md b/en/functions/higher_order.md index 49183757..66984ad9 100644 --- a/en/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/en/loops/for.md b/en/loops/for.md index 8b4487d5..4dbd89e7 100644 --- a/en/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/en/loops/while.md b/en/loops/while.md index 8d6db0aa..bcc3ffb0 100644 --- a/en/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/en/numbers/advanced.md b/en/numbers/advanced.md index d8042818..12cad0e7 100644 --- a/en/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/en/numbers/create.md b/en/numbers/create.md index c4b62e3f..e5bfae69 100644 --- a/en/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/en/numbers/operators.md b/en/numbers/operators.md index 51f4e500..e6202271 100644 --- a/en/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/en/strings/concat.md b/en/strings/concat.md index 84ddd5b3..81c7a122 100644 --- a/en/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/en/strings/create.md b/en/strings/create.md index e303337e..79e07fcf 100644 --- a/en/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/en/strings/length.md b/en/strings/length.md index 93554813..b9932177 100644 --- a/en/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/en/strings/substrings.md b/en/strings/substrings.md index 6346187e..998c48a5 100644 --- a/en/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)); From 878276df0e5f6f273c28844ce419e2f3681e1425 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Sat, 14 Feb 2015 11:36:58 +0100 Subject: [PATCH 3/3] Improve repo readme --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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).