From fb5c7b6fa70a7dd0cd69bd8206195cab440e608b Mon Sep 17 00:00:00 2001 From: Brent Guffens Date: Wed, 17 Jan 2018 09:18:11 +0100 Subject: [PATCH 01/11] Minus operation instead of minus sign --- .../1-primitive-conversions-questions/solution.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/06-type-conversions/1-primitive-conversions-questions/solution.md b/1-js/02-first-steps/06-type-conversions/1-primitive-conversions-questions/solution.md index a4f3fec7..ce48cbff 100644 --- a/1-js/02-first-steps/06-type-conversions/1-primitive-conversions-questions/solution.md +++ b/1-js/02-first-steps/06-type-conversions/1-primitive-conversions-questions/solution.md @@ -17,6 +17,6 @@ undefined + 1 = NaN // (4) ``` 1. The addition with a string `"" + 1` converts `1` to a string: `"" + 1 = "1"`, and then we have `"1" + 0`, the same rule is applied. -2. The subtraction `"-"` (like most math operations) only works with numbers, it converts an empty string `""` to `0`. +2. The subtraction `-` (like most math operations) only works with numbers, it converts an empty string `""` to `0`. 3. `null` becomes `0` after the numeric conversion. 4. `undefined` becomes `NaN` after the numeric conversion. From 60ea5f6bc40ad77cfbf8e95fc5e006e084e9185d Mon Sep 17 00:00:00 2001 From: Brent Guffens Date: Wed, 17 Jan 2018 11:24:53 +0100 Subject: [PATCH 02/11] Remove quotes around unary negation operator --- 1-js/02-first-steps/07-operators/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/07-operators/article.md b/1-js/02-first-steps/07-operators/article.md index df24311c..4f8d8cec 100644 --- a/1-js/02-first-steps/07-operators/article.md +++ b/1-js/02-first-steps/07-operators/article.md @@ -11,7 +11,7 @@ In this chapter we concentrate on aspects that are not covered by school arithme Before we move on, let's grasp the common terminology. - *An operand* -- is what operators are applied to. For instance in multiplication `5 * 2` there are two operands: the left operand is `5`, and the right operand is `2`. Sometimes people say "arguments" instead of "operands". -- An operator is *unary* if it has a single operand. For example, the unary negation `"-"` reverses the sign of the number: +- An operator is *unary* if it has a single operand. For example, the unary negation `-` reverses the sign of the number: ```js run let x = 1; From 59f6d8d0a2d9381d75ba20822ff93528c1314551 Mon Sep 17 00:00:00 2001 From: Brent Guffens Date: Wed, 17 Jan 2018 11:26:56 +0100 Subject: [PATCH 03/11] Remove quotes around addition operator --- 1-js/02-first-steps/07-operators/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/07-operators/article.md b/1-js/02-first-steps/07-operators/article.md index 4f8d8cec..017f484c 100644 --- a/1-js/02-first-steps/07-operators/article.md +++ b/1-js/02-first-steps/07-operators/article.md @@ -34,7 +34,7 @@ Before we move on, let's grasp the common terminology. Now let's see special features of JavaScript operators that are beyond school arithmetics. -Usually the plus operator `'+'` sums numbers. +Usually the plus operator `+` sums numbers. But if the binary `+` is applied to strings, it merges (concatenates) them: From 2fb940557d59bfad7b40fc940ff4b365a2a20a70 Mon Sep 17 00:00:00 2001 From: Brent Guffens Date: Wed, 17 Jan 2018 11:29:07 +0100 Subject: [PATCH 04/11] Remove quotes around addition operator --- 1-js/02-first-steps/07-operators/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/07-operators/article.md b/1-js/02-first-steps/07-operators/article.md index 017f484c..74c88fa5 100644 --- a/1-js/02-first-steps/07-operators/article.md +++ b/1-js/02-first-steps/07-operators/article.md @@ -54,7 +54,7 @@ alert( 2 + '1' ); // "21" See, it doesn't matter whether the first operand is a string or the second one. The rule is simple: if either operand is a string, then convert the other one into a string as well. -String concatenation and conversion is a special feature of the binary plus `"+"`. Other arithmetic operators work only with numbers. They always convert their operands to numbers. +String concatenation and conversion is a special feature of the binary plus `+`. Other arithmetic operators work only with numbers. They always convert their operands to numbers. For instance, subtraction and division: From 2c3b1a34e23c66fdbe623ed26ae92564b563ba22 Mon Sep 17 00:00:00 2001 From: Brent Guffens Date: Wed, 17 Jan 2018 11:32:49 +0100 Subject: [PATCH 05/11] Number to string conversion clarification --- 1-js/02-first-steps/07-operators/article.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/1-js/02-first-steps/07-operators/article.md b/1-js/02-first-steps/07-operators/article.md index 74c88fa5..3b86dfa1 100644 --- a/1-js/02-first-steps/07-operators/article.md +++ b/1-js/02-first-steps/07-operators/article.md @@ -43,7 +43,7 @@ let s = "my" + "string"; alert(s); // mystring ``` -Note that if any of operands is a string, then the other one is converted to a string too. +Note that if any of the operands is a string, then the other one is converted to a string too. For example: @@ -54,6 +54,13 @@ alert( 2 + '1' ); // "21" See, it doesn't matter whether the first operand is a string or the second one. The rule is simple: if either operand is a string, then convert the other one into a string as well. +However, note that operations run from left to right. If there are two numbers followed by a string, the numbers will be added before being converted to a string: + + +```js run +alert(2 + 2 + '1' ); // "41" and not "221" +``` + String concatenation and conversion is a special feature of the binary plus `+`. Other arithmetic operators work only with numbers. They always convert their operands to numbers. For instance, subtraction and division: From 0f42ea7b1203fd0430c5332fa01cf00287cc502c Mon Sep 17 00:00:00 2001 From: Brent Guffens Date: Wed, 17 Jan 2018 11:35:49 +0100 Subject: [PATCH 06/11] Typo fix --- 1-js/02-first-steps/07-operators/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/07-operators/article.md b/1-js/02-first-steps/07-operators/article.md index 3b86dfa1..39c2eb52 100644 --- a/1-js/02-first-steps/07-operators/article.md +++ b/1-js/02-first-steps/07-operators/article.md @@ -72,7 +72,7 @@ alert( '6' / '2' ); // 3 ## Numeric conversion, unary + -The plus `+` exist in two forms. The binary form that we used above and the unary form. +The plus `+` exists in two forms. The binary form that we used above and the unary form. The unary plus or, in other words, the plus operator `+` applied to a single value, doesn't do anything with numbers, but if the operand is not a number, then it is converted into it. From abef5c437956998172a003977b470118228b9d5e Mon Sep 17 00:00:00 2001 From: Brent Guffens Date: Wed, 17 Jan 2018 11:43:11 +0100 Subject: [PATCH 07/11] More language improvements --- 1-js/02-first-steps/07-operators/article.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/1-js/02-first-steps/07-operators/article.md b/1-js/02-first-steps/07-operators/article.md index 39c2eb52..138b6cfd 100644 --- a/1-js/02-first-steps/07-operators/article.md +++ b/1-js/02-first-steps/07-operators/article.md @@ -93,9 +93,9 @@ alert( +"" ); // 0 */!* ``` -It actually does the same as `Number(...)`, but shorter. +It actually does the same as `Number(...)`, but is shorter. -A need to convert string to number arises very often. For example, if we are getting values from HTML form fields, then they are usually strings. +A need to convert strings to numbers arises very often. For example, if we are getting values from HTML form fields, then they are usually strings. What if we want to sum them? From 61094487682a6cd04bfc03406125c7d247c72a5d Mon Sep 17 00:00:00 2001 From: Brent Guffens Date: Wed, 17 Jan 2018 12:43:14 +0100 Subject: [PATCH 08/11] Remove quotes around comma operator --- 1-js/02-first-steps/07-operators/article.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/1-js/02-first-steps/07-operators/article.md b/1-js/02-first-steps/07-operators/article.md index 138b6cfd..17a807af 100644 --- a/1-js/02-first-steps/07-operators/article.md +++ b/1-js/02-first-steps/07-operators/article.md @@ -253,14 +253,14 @@ So, there are special operators for that: ```js run no-beautify let counter = 2; - counter++; // works same as counter = counter + 1, but shorter + counter++; // works the same as counter = counter + 1, but is shorter alert( counter ); // 3 ``` - **Decrement** `--` decreases a variable by 1: ```js run no-beautify let counter = 2; - counter--; // works same as counter = counter - 1, but shorter + counter--; // works the same as counter = counter - 1, but is shorter alert( counter ); // 1 ``` @@ -408,9 +408,9 @@ alert( n ); // 16 (right part evaluated first, same as n *= 8) ## Comma -The comma operator `','` is one of most rare and unusual operators. Sometimes it's used to write shorter code, so we need to know it in order to understand what's going on. +The comma operator `,` is one of most rare and unusual operators. Sometimes it's used to write shorter code, so we need to know it in order to understand what's going on. -The comma operator allows us to evaluate several expressions, dividing them with a comma `','`. Each of them is evaluated, but the result of only the last one is returned. +The comma operator allows us to evaluate several expressions, dividing them with a comma `,`. Each of them is evaluated, but the result of only the last one is returned. For example: From 4a00819e87b8cb903fae1f9d7cfdd4aca2c0c532 Mon Sep 17 00:00:00 2001 From: Brent Guffens Date: Sun, 21 Jan 2018 13:07:53 +0100 Subject: [PATCH 09/11] Sentence in the wrong task --- 1-js/05-data-types/02-number/8-random-min-max/task.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/1-js/05-data-types/02-number/8-random-min-max/task.md b/1-js/05-data-types/02-number/8-random-min-max/task.md index cde399db..7037cfcb 100644 --- a/1-js/05-data-types/02-number/8-random-min-max/task.md +++ b/1-js/05-data-types/02-number/8-random-min-max/task.md @@ -15,5 +15,3 @@ alert( random(1, 5) ); // 1.2345623452 alert( random(1, 5) ); // 3.7894332423 alert( random(1, 5) ); // 4.3435234525 ``` - -You can use the solution of the [previous task](info:task/random-min-max) as the base. \ No newline at end of file From aeabf4bf9bd550fb818c650c8f429387f9009095 Mon Sep 17 00:00:00 2001 From: Brent Guffens Date: Sun, 21 Jan 2018 13:08:31 +0100 Subject: [PATCH 10/11] Added instruction to correct task. --- 1-js/05-data-types/02-number/9-random-int-min-max/task.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/1-js/05-data-types/02-number/9-random-int-min-max/task.md b/1-js/05-data-types/02-number/9-random-int-min-max/task.md index 71d83f01..29341b2a 100644 --- a/1-js/05-data-types/02-number/9-random-int-min-max/task.md +++ b/1-js/05-data-types/02-number/9-random-int-min-max/task.md @@ -15,4 +15,6 @@ Examples of its work: alert( random(1, 5) ); // 1 alert( random(1, 5) ); // 3 alert( random(1, 5) ); // 5 -``` \ No newline at end of file +``` + +You can use the solution of the [previous task](info:task/random-min-max) as the base. From 7f8b27daef4761578a020d3edd09c07fa3891076 Mon Sep 17 00:00:00 2001 From: Brent Guffens Date: Sun, 21 Jan 2018 13:42:18 +0100 Subject: [PATCH 11/11] Typo --- 1-js/05-data-types/02-number/9-random-int-min-max/solution.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/05-data-types/02-number/9-random-int-min-max/solution.md b/1-js/05-data-types/02-number/9-random-int-min-max/solution.md index 1b007032..0950ff81 100644 --- a/1-js/05-data-types/02-number/9-random-int-min-max/solution.md +++ b/1-js/05-data-types/02-number/9-random-int-min-max/solution.md @@ -27,7 +27,7 @@ Now we can clearly see that `1` gets twice less values than `2`. And the same wi # The correct solution -There are many correct solutions to the task. One of them is to adjust interval borders. To ensure the same intervals, we can generate values from `0.5 to 2.5`, thus adding the required probabilities to the edges: +There are many correct solutions to the task. One of them is to adjust interval borders. To ensure the same intervals, we can generate values from `0.5 to 3.5`, thus adding the required probabilities to the edges: ```js run *!*