◐ Shell
reader mode source ↗
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
6 changes: 3 additions & 3 deletions 1-js/04-object-basics/01-object/2-hello-object/solution.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

```js
let user = {};
user.name = "John";
user.surname = "Smith";
user.name = "Pete";
delete user.name;
```

14 changes: 7 additions & 7 deletions 1-js/04-object-basics/01-object/2-hello-object/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ importance: 5

---

# Hello, object

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.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function isEmpty(obj) {
for (let key in obj) {
// if the loop has started, there is a property
return false;
}
return true;
Expand Down
6 changes: 3 additions & 3 deletions 1-js/04-object-basics/01-object/3-is-empty/_js.view/test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
describe("isEmpty", function() {
it("returns true for an empty object", function() {
assert.isTrue(isEmpty({}));
});

it("returns false if a property exists", function() {
assert.isFalse(isEmpty({
anything: false
}));
Expand Down
8 changes: 4 additions & 4 deletions 1-js/04-object-basics/01-object/3-is-empty/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ importance: 5

---

# Check for emptiness

Write the function `isEmpty(obj)` which returns `true` if the object has no properties, `false` otherwise.

Should work like that:

```js
let schedule = {};

alert( isEmpty(schedule) ); // true

schedule["8:30"] = "get up";

alert( isEmpty(schedule) ); // false
```
Expand Down
8 changes: 4 additions & 4 deletions 1-js/04-object-basics/01-object/5-sum-object/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ importance: 5

---

# Sum object properties

We have an object storing salaries of our team:

```js
let salaries = {
Expand All @@ -14,6 +14,6 @@ let salaries = {
}
```

Write the code to sum all salaries and store in the variable `sum`. Should be `390` in the example above.

If `salaries` is empty, then the result must be `0`.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
let menu = {
width: 200,
height: 300,
title: "My menu"
};


function multiplyNumeric(obj) {

/* your code */

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
describe("multiplyNumeric", function() {
it("multiplies all numeric properties by 2", function() {
let menu = {
width: 200,
height: 300,
title: "My menu"
};
let result = multiplyNumeric(menu);
assert.equal(menu.width, 400);
assert.equal(menu.height, 600);
assert.equal(menu.title, "My menu");
});

it("returns nothing", function() {
assert.isUndefined( multiplyNumeric({}) );
});

});
18 changes: 9 additions & 9 deletions 1-js/04-object-basics/01-object/8-multiply-numeric/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,32 @@ importance: 3

---

# Multiply numeric property values by 2

Create a function `multiplyNumeric(obj)` that multiplies all numeric property values of `obj` by `2`.

For instance:

```js
// before the call
let menu = {
width: 200,
height: 300,
title: "My menu"
};

multiplyNumeric(menu);

// after the call
menu = {
width: 400,
height: 600,
title: "My menu"
};
```

Please note that `multiplyNumeric` does not need to return anything. It should modify the object in-place.

P.S. Use `typeof` to check for a number here.


Loading
Toggle all file notes Toggle all file annotations