Skip to content

Commit b294742

Browse files
committed
All is done
1 parent f21e0e5 commit b294742

File tree

11 files changed

+66
-16
lines changed

11 files changed

+66
-16
lines changed

Exercises/1-let.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
// Define variable to store your name as a string
44

5-
let name = undefined;
5+
let name = 'Denis';
66

77
module.exports = { name };

Exercises/2-const.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
// Define constant to store your birth year as a number
44

5-
const year = undefined;
5+
const year = 1980;
66

77
module.exports = { year };

Exercises/3-hello.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
// Prepare function to print greeting with single argument
44

5-
const hello = null;
5+
const hello = (name) => console.log(`Hello ${name}!`);
66

77
module.exports = { hello };

Exercises/4-range.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
// Implement function `range(start: number, end: number): array` returning
44
// array with all numbers from the range [15, 30] including endpoints
55

6-
const range = null;
6+
const range = (start, end) => {
7+
const result = [];
8+
for (let i = start; i <= end; i++) {
9+
result.push(i);
10+
}
11+
return result;
12+
};
13+
14+
// const result = range(1, 10);
15+
// console.log({ result });
716

817
module.exports = { range };

Exercises/5-range-odd.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
// Implement function `rangeOdd(start: number, end: number)` returning
44
// array with all odd numbers from the range [15, 30] including endpoints
55

6-
const rangeOdd = null;
6+
const rangeOdd = (start, end) => {
7+
const result = [];
8+
for (let i = start; i <= end; i++) {
9+
if (i % 2 === 0) continue;
10+
result.push(i);
11+
}
12+
return result;
13+
};
714

815
module.exports = { rangeOdd };

Exercises/6-calculate.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,18 @@
1616
Call functions `square` and `cube` in loop, then pass their
1717
results to function `average`. Print what `average` returns. */
1818

19-
const square = null;
19+
const square = (x) => x * x;
2020

21-
const cube = null;
21+
const cube = (x) => x ** 3;
2222

23-
const average = null;
23+
const average = (a, b) => (a + b) / 2;
2424

25-
const calculate = null;
25+
const calculate = () => {
26+
const result = [];
27+
for (let i = 0; i < 10; i++) {
28+
result.push(average(square(i), cube(i)));
29+
}
30+
return result;
31+
};
2632

2733
module.exports = { square, cube, average, calculate };

Exercises/7-objects.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@
77
- Try to assign other object to both identifiers.
88
- Explain script behaviour. */
99

10-
const fn = null;
10+
const fn = () => {
11+
const obj1 = {
12+
name: 'Denis',
13+
};
14+
let obj2 = {
15+
name: 'Milana',
16+
};
17+
obj1.name = 'Vasia';
18+
obj2.name = 'Alisa';
19+
//obj1 = {};
20+
obj2 = {};
21+
};
22+
23+
1124

1225
module.exports = { fn };

Exercises/8-create.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
Example: `createUser('Marcus Aurelius', 'Roma')`
66
will return object `{ name: 'Marcus Aurelius', city: 'Roma' }` */
77

8-
const createUser = null;
8+
const createUser = (name, city) => ({ name, city });
99

1010
module.exports = { createUser };

Exercises/9-array.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,20 @@ Object example: `{ name: 'Marcus Aurelius', phone: '+380445554433' }`.
99
`findPhoneByName(name: string): string`. Returning phone from that object
1010
where field `name` equals argument `name`. Use `for` loop for this search. */
1111

12-
const phonebook = null;
12+
const phonebook = [
13+
{ name: 'Marcus Aurelius', phone: '+380445554433' },
14+
{ name: 'Denis Vasilenko', phone: '+79673196182' },
15+
{ name: 'Milane Ganeeva', phone: '+78934832938' },
16+
];
17+
18+
const findPhoneByName = (name) => {
19+
for (const user of phonebook) {
20+
if (user.name === name) return user.phone;
21+
}
22+
};
23+
24+
console.log(findPhoneByName('Denis Vasilenko'));
25+
1326

14-
const findPhoneByName = null;
1527

1628
module.exports = { phonebook, findPhoneByName };

Exercises/a-hash.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ contains `phone`.
77
`findPhoneByName(name: string): string`. Returning phone from hash/object.
88
Use `hash[key]` to find needed phone. */
99

10-
const phonebook = null;
10+
const phonebook = {
11+
Marcus: '+380445554433',
12+
Denis: '+79673196182',
13+
};
1114

12-
const findPhoneByName = null;
15+
const findPhoneByName = (name) => phonebook[name];
1316

1417
module.exports = { phonebook, findPhoneByName };

JavaScript/2-loop.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ const MAX_VALUE = 10;
44

55
console.log('Begin');
66
for (let i = 0; i < MAX_VALUE; i++) {
7-
console.dir({ i, date: new Date() });
7+
console.dir({ counter: i, date: new Date() });
88
}
99
console.log('The end');

0 commit comments

Comments
 (0)