Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Objects#118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
otmon76 merged 1 commit intojavascript-tutorial:masterfromotmon76:1.4.1
Jun 3, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions1-js/04-object-basics/01-object/2-hello-object/solution.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@


```js
letuser = {};
user.name = "John";
user.surname = "Smith";
user.name = "Pete";
deleteuser.name;
letuživatel = {};
uživatel.jméno = "Jan";
uživatel.příjmení = "Novák";
uživatel.jméno = "Petr";
deleteuživatel.jméno;
```

15 changes: 7 additions & 8 deletions1-js/04-object-basics/01-object/2-hello-object/task.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,13 +2,12 @@ importance: 5

---

#Hello, object
#Ahoj, objekte

Write the code, one line for each action:

1. Create an empty object `user`.
2. Add the property `name` with the value `John`.
3. Add the property `surname` with the value `Smith`.
4. Change the value of the `name` to `Pete`.
5. Remove the property `name` from the object.
Napište tento kód, pro každou akci jeden řádek:

1. Vytvořte prázdný objekt `uživatel`.
2. Přidejte vlastnost `jméno` s hodnotou `Jan`.
3. Přidejte vlastnost `příjmení` s hodnotou `Novák`.
4. Změňte hodnotu vlastnosti `jméno` na `Petr`.
5. Odstraňte vlastnost `jméno` z objektu.
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
functionisEmpty(obj) {
for (letkey in obj) {
//if the loop has started, there is a property
functionjePrázdný(obj) {
for (letklíč in obj) {
//pokud cyklus začal, je tam nějaká vlastnost
return false;
}
return true;
Expand Down
12 changes: 6 additions & 6 deletions1-js/04-object-basics/01-object/3-is-empty/_js.view/test.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
describe("isEmpty", function() {
it("returns truefor an empty object", function() {
assert.isTrue(isEmpty({}));
describe("jePrázdný", function() {
it("vrátí truepro prázdný objekt", function() {
assert.isTrue(jePrázdný({}));
});

it("returns false if a property exists", function() {
assert.isFalse(isEmpty({
anything: false
it("vrátí false, jestliže existuje nějaká vlastnost", function() {
assert.isFalse(jePrázdný({
cokoli: false
}));
});
});
2 changes: 1 addition & 1 deletion1-js/04-object-basics/01-object/3-is-empty/solution.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
Just loop over the object and `return false` immediately if there's at least one property.
Prostě proveďte cyklus nad objektem, a má-li aspoň jednu vlastnost, okamžitě proveďte `return false`.
14 changes: 7 additions & 7 deletions1-js/04-object-basics/01-object/3-is-empty/task.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,19 +2,19 @@ importance: 5

---

#Check for emptiness
#Ověření prázdnoty

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

Should work like that:
Měla by fungovat takto:

```js
letschedule = {};
letrozvrh = {};

alert(isEmpty(schedule) ); // true
alert(jePrázdný(rozvrh) ); // true

schedule["8:30"] = "get up";
rozvrh["8:30"] = "vstát";

alert(isEmpty(schedule) ); // false
alert(jePrázdný(rozvrh) ); // false
```

16 changes: 8 additions & 8 deletions1-js/04-object-basics/01-object/5-sum-object/solution.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@

```js run
letsalaries = {
John: 100,
Ann: 160,
Pete: 130
letplaty = {
Jan: 100,
Anna: 160,
Petr: 130
};

letsum = 0;
for (letkey insalaries) {
sum +=salaries[key];
letsoučet = 0;
for (letklíč inplaty) {
součet +=platy[klíč];
}

alert(sum); // 390
alert(součet); // 390
```

16 changes: 8 additions & 8 deletions1-js/04-object-basics/01-object/5-sum-object/task.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,18 +2,18 @@ importance: 5

---

#Sum object properties
#Sečtěte vlastnosti objektu

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

```js
letsalaries = {
John: 100,
Ann: 160,
Pete: 130
letplaty = {
Jan: 100,
Anna: 160,
Petr: 130
}
```

Write the code to sum all salaries and store in the variable `sum`.Should be `390` in the example above.
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`.

If `salaries` is empty, then the result must be `0`.
Je-li objekt `platy` prázdný, výsledek musí být `0`.
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
functionmultiplyNumeric(obj) {
for (letkey in obj) {
if (typeof obj[key] == 'number') {
obj[key] *= 2;
functionvynásobČísla(obj) {
for (letklíč in obj) {
if (typeof obj[klíč] == 'number') {
obj[klíč] *= 2;
}
}
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
let menu = {
width: 200,
height: 300,
title: "My menu"
šířka: 200,
výška: 300,
titulek: "Moje menu"
};


functionmultiplyNumeric(obj) {
functionvynásobČísla(obj) {

/*your code */
/*váš kód */

}

multiplyNumeric(menu);
vynásobČísla(menu);

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

View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
describe("multiplyNumeric",function(){
it("multiplies all numeric properties by 2",function(){
describe("vynásobČísla",function(){
it("vynásobí všechny číselné vlastnosti dvěma",function(){
letmenu={
width:200,
height:300,
title:"My menu"
šířka:200,
výška:300,
titulek:"Moje menu"
};
letresult=multiplyNumeric(menu);
assert.equal(menu.width,400);
assert.equal(menu.height,600);
assert.equal(menu.title,"My menu");
letvýsledek=vynásobČísla(menu);
assert.equal(menu.šířka,400);
assert.equal(menu.výška,600);
assert.equal(menu.titulek,"Moje menu");
});

it("returns nothing",function(){
assert.isUndefined(multiplyNumeric({}));
it("nevrátí nic",function(){
assert.isUndefined(vynásobČísla({}));
});

});
28 changes: 14 additions & 14 deletions1-js/04-object-basics/01-object/8-multiply-numeric/task.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,32 +2,32 @@ importance: 3

---

#Multiply numeric property values by 2
#Vynásobte hodnoty číselných vlastností dvěma

Create a function `multiplyNumeric(obj)` that multiplies all numeric property values of `obj`by `2`.
Vytvořte funkci `vynásobČísla(obj)`, která vynásobí hodnoty všech číselných vlastností objektu `obj`dvěma.

For instance:
Například:

```js
//before the call
//před voláním
let menu = {
width: 200,
height: 300,
title: "My menu"
šířka: 200,
výška: 300,
titulek: "Moje menu"
};

multiplyNumeric(menu);
vynásobČísla(menu);

//after the call
//po volání
menu = {
width: 400,
height: 600,
title: "My menu"
šířka: 400,
výška: 600,
titulek: "Moje menu"
};
```

Please note that `multiplyNumeric` does not need to return anything. It should modify the object in-place.
Prosíme všimněte si, že `vynásobČísla` nemusí nic vracet. Měla by modifikovat samotný objekt.

P.S.Use `typeof` to check for a number here.
P.S.Pro kontrolu, zda hodnota je číslo, použijte `typeof`.


Loading

[8]ページ先頭

©2009-2025 Movatter.jp