Update from source
Merge branch 'master' of https://github.com/iliakan/javascript-tutorial-en
This commit is contained in:
commit
26ec750878
10 changed files with 16 additions and 16 deletions
|
@ -13,7 +13,7 @@ function pow(x, n) {
|
|||
let x = prompt("x?", '');
|
||||
let n = prompt("n?", '');
|
||||
|
||||
if (n <= 1) {
|
||||
if (n < 1) {
|
||||
alert(`Power ${n} is not supported,
|
||||
use an integer greater than 0`);
|
||||
} else {
|
||||
|
|
|
@ -9,7 +9,7 @@ Write a function `pow(x,n)` that returns `x` in power `n`. Or, in other words, m
|
|||
```js
|
||||
pow(3, 2) = 3 * 3 = 9
|
||||
pow(3, 3) = 3 * 3 * 3 = 27
|
||||
pow(1, 100) = 1 * 1 * ...*1 = 1
|
||||
pow(1, 100) = 1 * 1 * ...* 1 = 1
|
||||
```
|
||||
|
||||
Create a web-page that prompts for `x` and `n`, and then shows the result of `pow(x,n)`.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
describe("truncate", function() {
|
||||
it("truncate the long string to the given lenth (including the ellipsis)", function() {
|
||||
it("truncate the long string to the given length (including the ellipsis)", function() {
|
||||
assert.equal(
|
||||
truncate("What I'd like to tell on this topic is:", 20),
|
||||
"What I'd like to te…"
|
||||
|
@ -13,4 +13,4 @@ describe("truncate", function() {
|
|||
);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
|
|
@ -4,7 +4,7 @@ importance: 5
|
|||
|
||||
# European weekday
|
||||
|
||||
European countries have days of week starting with monday (number 1), then tuesday (number 2) and till sunday (number 7). Write a function `getLocalDay(date)` that returns the "european" day of week for `date`.
|
||||
European countries have days of week starting with Monday (number 1), then Tuesday (number 2) and till Sunday (number 7). Write a function `getLocalDay(date)` that returns the "European" day of week for `date`.
|
||||
|
||||
```js no-beautify
|
||||
let date = new Date(2012, 0, 3); // 3 Jan 2012
|
||||
|
|
|
@ -131,7 +131,7 @@ let meetup = {
|
|||
title: "Conference",
|
||||
*!*
|
||||
room: {
|
||||
number: 123,
|
||||
number: 23,
|
||||
participants: ["john", "ann"]
|
||||
}
|
||||
*/!*
|
||||
|
|
|
@ -135,7 +135,7 @@ alert( Math.max(3, 5, 1) ); // 5
|
|||
|
||||
Now let's say we have an array `[3, 5, 1]`. How do we call `Math.max` with it?
|
||||
|
||||
Passing it "as it" won't work, because `Math.max` expects a list of numeric arguments, not a single array:
|
||||
Passing it "as is" won't work, because `Math.max` expects a list of numeric arguments, not a single array:
|
||||
|
||||
```js run
|
||||
let arr = [3, 5, 1];
|
||||
|
@ -145,7 +145,7 @@ alert( Math.max(arr) ); // NaN
|
|||
*/!*
|
||||
```
|
||||
|
||||
And surely we can't manually list items in the code `Math.max(arg[0], arg[1], arg[2])`, because we may be unsure how many there are. As our script executes, there could be a lot, or there could be none. And that would get ugly.
|
||||
And surely we can't manually list items in the code `Math.max(arr[0], arr[1], arr[2])`, because we may be unsure how many there are. As our script executes, there could be a lot, or there could be none. And that would get ugly.
|
||||
|
||||
*Spread operator* to the rescue! It looks similar to rest parameters, also using `...`, but does quite the opposite.
|
||||
|
||||
|
|
|
@ -7,9 +7,9 @@ libs:
|
|||
|
||||
# Walking the DOM
|
||||
|
||||
DOM allows to do anything with elements and their contents, but first we need to reach the corresponding DOM object, get it into a variable, and then we are able to modify it.
|
||||
The DOM allows to do anything with elements and their contents, but first we need to reach the corresponding DOM object, get it into a variable, and then we are able to modify it.
|
||||
|
||||
All operations on DOM start with the `document` object. From it we can access any node.
|
||||
All operations on the DOM start with the `document` object. From it we can access any node.
|
||||
|
||||
Here's a picture of links that allow to travel between DOM nodes:
|
||||
|
||||
|
@ -273,7 +273,7 @@ Certain types of DOM elements may provide additional properties, specific to the
|
|||
|
||||
Tables are a great example and important particular case of that.
|
||||
|
||||
**`<table>`** element supports (in addition to the given above) these properties:
|
||||
**The `<table>`** element supports (in addition to the given above) these properties:
|
||||
- `table.rows` -- the collection of `<tr>` elements of the table.
|
||||
- `table.caption/tHead/tFoot` -- references to elements `<caption>`, `<thead>`, `<tfoot>`.
|
||||
- `table.tBodies` -- the collection of `<tbody>` elements (can be many according to the standard).
|
||||
|
@ -283,8 +283,8 @@ Tables are a great example and important particular case of that.
|
|||
|
||||
**`<tr>`:**
|
||||
- `tr.cells` -- the collection of `<td>` and `<th>` cells inside the given `<tr>`.
|
||||
- `tr.sectionRowIndex` -- the number of the given `<tr>` inside the enclosing `<thead>/<tbody>`.
|
||||
- `tr.rowIndex` -- the number of the `<tr>` in the table.
|
||||
- `tr.sectionRowIndex` -- the position (index) of the given `<tr>` inside the enclosing `<thead>/<tbody>/<tfoot>`.
|
||||
- `tr.rowIndex` -- the number of the `<tr>` in the table as a whole (including all table rows).
|
||||
|
||||
**`<td>` and `<th>`:**
|
||||
- `td.cellIndex` -- the number of the cell inside the enclosing `<tr>`.
|
||||
|
|
|
@ -55,7 +55,7 @@ If we compare window coordinates versus CSS positioning, then there are obvious
|
|||
|
||||
But in CSS the `right` property means the distance from the right edge, and the `bottom` -- from the bottom edge.
|
||||
|
||||
If we just look at the picture below, we can see that in JavaScript it is not so. All window coordinates are counted from the upper-left corner, including these ones.
|
||||
If we just look at the picture above, we can see that in JavaScript it is not so. All window coordinates are counted from the upper-left corner, including these ones.
|
||||
```
|
||||
|
||||
## elementFromPoint(x, y) [#elementFromPoint]
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
# Event delegation
|
||||
|
||||
Capturing and bubbling allow to implement one of most powerful event handling patterns called *event delegation*.
|
||||
Capturing and bubbling allow us to implement one of most powerful event handling patterns called *event delegation*.
|
||||
|
||||
The idea is that if we have a lot of elements handled in a similar way, then instead of assigning a handler to each of them -- we put a single handler on their common ancestor.
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# Error in setTimeout
|
||||
|
||||
How do you think, does the `.catch` trigger? Explain your answer?
|
||||
What do you think? Will the `.catch` trigger? Explain your answer.
|
||||
|
||||
```js
|
||||
new Promise(function(resolve, reject) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue