Skip to content

Commit 83bceb1

Browse files
authored
Merge pull request #118 from otmon76/1.4.1
Objects
2 parents 531d77c + 64b820e commit 83bceb1

File tree

19 files changed

+313
-314
lines changed

19 files changed

+313
-314
lines changed
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11

22

33
```js
4-
let user = {};
5-
user.name = "John";
6-
user.surname = "Smith";
7-
user.name = "Pete";
8-
delete user.name;
4+
let uživatel = {};
5+
ivatel.jméno = "Jan";
6+
ivatel.příjmení = "Novák";
7+
ivatel.jméno = "Petr";
8+
delete ivatel.jméno;
99
```
1010

1-js/04-object-basics/01-object/2-hello-object/task.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ importance: 5
22

33
---
44

5-
# Hello, object
5+
# Ahoj, objekte
66

7-
Write the code, one line for each action:
8-
9-
1. Create an empty object `user`.
10-
2. Add the property `name` with the value `John`.
11-
3. Add the property `surname` with the value `Smith`.
12-
4. Change the value of the `name` to `Pete`.
13-
5. Remove the property `name` from the object.
7+
Napište tento kód, pro každou akci jeden řádek:
148

9+
1. Vytvořte prázdný objekt `uživatel`.
10+
2. Přidejte vlastnost `jméno` s hodnotou `Jan`.
11+
3. Přidejte vlastnost `příjmení` s hodnotou `Novák`.
12+
4. Změňte hodnotu vlastnosti `jméno` na `Petr`.
13+
5. Odstraňte vlastnost `jméno` z objektu.

1-js/04-object-basics/01-object/3-is-empty/_js.view/solution.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
function isEmpty(obj) {
2-
for (let key in obj) {
3-
// if the loop has started, there is a property
1+
function jePrázdný(obj) {
2+
for (let klíč in obj) {
3+
// pokud cyklus začal, je tam nějaká vlastnost
44
return false;
55
}
66
return true;
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
describe("isEmpty", function() {
2-
it("returns true for an empty object", function() {
3-
assert.isTrue(isEmpty({}));
1+
describe("jePrázdný", function() {
2+
it("vrátí true pro prázdný objekt", function() {
3+
assert.isTrue(jePrázdný({}));
44
});
55

6-
it("returns false if a property exists", function() {
7-
assert.isFalse(isEmpty({
8-
anything: false
6+
it("vrátí false, jestliže existuje nějaká vlastnost", function() {
7+
assert.isFalse(jePrázdný({
8+
cokoli: false
99
}));
1010
});
1111
});
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Just loop over the object and `return false` immediately if there's at least one property.
1+
Prostě proveďte cyklus nad objektem, a má-li aspoň jednu vlastnost, okamžitě proveďte `return false`.

1-js/04-object-basics/01-object/3-is-empty/task.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ importance: 5
22

33
---
44

5-
# Check for emptiness
5+
# Ověření prázdnoty
66

7-
Write the function `isEmpty(obj)` which returns `true` if the object has no properties, `false` otherwise.
7+
Napište funkci `jePrázdný(obj)`, která vrátí `true`, jestliže objekt nemá žádné vlastnosti, a `false` jinak.
88

9-
Should work like that:
9+
Měla by fungovat takto:
1010

1111
```js
12-
let schedule = {};
12+
let rozvrh = {};
1313

14-
alert( isEmpty(schedule) ); // true
14+
alert( jePrázdný(rozvrh) ); // true
1515

16-
schedule["8:30"] = "get up";
16+
rozvrh["8:30"] = "vstát";
1717

18-
alert( isEmpty(schedule) ); // false
18+
alert( jePrázdný(rozvrh) ); // false
1919
```
2020

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11

22
```js run
3-
let salaries = {
4-
John: 100,
5-
Ann: 160,
6-
Pete: 130
3+
let platy = {
4+
Jan: 100,
5+
Anna: 160,
6+
Petr: 130
77
};
88

9-
let sum = 0;
10-
for (let key in salaries) {
11-
sum += salaries[key];
9+
let součet = 0;
10+
for (let klíč in platy) {
11+
součet += platy[klíč];
1212
}
1313

14-
alert(sum); // 390
14+
alert(součet); // 390
1515
```
1616

1-js/04-object-basics/01-object/5-sum-object/task.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ importance: 5
22

33
---
44

5-
# Sum object properties
5+
# Sečtěte vlastnosti objektu
66

7-
We have an object storing salaries of our team:
7+
Máme objekt, v němž jsou uloženy platy našeho týmu:
88

99
```js
10-
let salaries = {
11-
John: 100,
12-
Ann: 160,
13-
Pete: 130
10+
let platy = {
11+
Jan: 100,
12+
Anna: 160,
13+
Petr: 130
1414
}
1515
```
1616

17-
Write the code to sum all salaries and store in the variable `sum`. Should be `390` in the example above.
17+
Napište kód, který všechny platy sečte a uloží do proměnné `součet`. Ve výše uvedeném příkladu by mělo vyjít `390`.
1818

19-
If `salaries` is empty, then the result must be `0`.
19+
Je-li objekt `platy` prázdný, výsledek musí být `0`.
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
function multiplyNumeric(obj) {
2-
for (let key in obj) {
3-
if (typeof obj[key] == 'number') {
4-
obj[key] *= 2;
1+
function vynásobČísla(obj) {
2+
for (let klíč in obj) {
3+
if (typeof obj[klíč] == 'number') {
4+
obj[klíč] *= 2;
55
}
66
}
77
}
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
let menu = {
2-
width: 200,
3-
height: 300,
4-
title: "My menu"
2+
šířka: 200,
3+
výška: 300,
4+
titulek: "Moje menu"
55
};
66

77

8-
function multiplyNumeric(obj) {
8+
function vynásobČísla(obj) {
99

10-
/* your code */
10+
/* váš kód */
1111

1212
}
1313

14-
multiplyNumeric(menu);
14+
vynásobČísla(menu);
1515

16-
alert( "menu width=" + menu.width + " height=" + menu.height + " title=" + menu.title );
16+
alert( "menu šířka=" + menu.šířka + " výška=" + menu.výška + " titulek=" + menu.titulek );
1717

0 commit comments

Comments
 (0)