Skip to content

Commit 24554c6

Browse files
author
Elena Kononchuk
committed
repo with tasks HowProgrammingWorks#2
1 parent 7d559ed commit 24554c6

10 files changed

+78
-25
lines changed

Exercises/1-let.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
'use strict';
1+
"use strict";
22

3-
let name = 'Elena';
3+
let name = "Elena";
44

55
module.exports = { name };

Exercises/2-const.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'use strict';
1+
"use strict";
22

33
const year = 1987;
44

Exercises/3-hello.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
'use strict';
1+
"use strict";
22

3-
const hello = name => 'Hello' + hello('Elena');
3+
const hello = (name) => {
4+
console.log(`Greeting for ${name}`);
5+
};
46

57
module.exports = { hello };

Exercises/4-range.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
'use strict';
1+
"use strict";
22

3-
const range = null;
3+
const range = (start, end) => {
4+
let array = [];
5+
for (let i = start; i <= end; i++) {
6+
array.push(i);
7+
}
8+
return array;
9+
};
410

511
module.exports = { range };

Exercises/5-range-odd.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1-
'use strict';
1+
"use strict";
22

3-
const rangeOdd = null;
3+
const rangeOdd = (start, end) => {
4+
let array = [];
5+
for (let i = start; i <= end; i++) {
6+
if (i % 2 !== 0) {
7+
array.push(i);
8+
}
9+
}
10+
return array;
11+
};
12+
//console.log(rangeOdd(0, 5));
413

514
module.exports = { rangeOdd };

Exercises/6-calculate.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
'use strict';
1+
"use strict";
22

3-
const square = null;
3+
const square = (x) => x * x;
44

5-
const cube = null;
5+
const cube = (x) => x ** 3;
66

7-
const average = null;
8-
9-
const calculate = null;
7+
const average = (a, b) => (a + b) / 2;
8+
let array = [];
9+
const calculate = () => {
10+
for (let i = 0; i <= 9; i++) {
11+
array.push(average(square(i), cube(i)));
12+
}
13+
return array;
14+
};
1015

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

Exercises/7-objects.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1-
'use strict';
1+
"use strict";
22

3-
const fn = null;
3+
const fn = () => {
4+
const obj1 = { name: "Kate" };
5+
let obj2 = { name: "Kate" };
6+
7+
obj1.name = "Winslet";
8+
obj2.name = "Winslet";
9+
10+
const obj3 = "Kate Winslet";
11+
12+
console.log(obj1, obj2, obj3);
13+
};
414

515
module.exports = { fn };

Exercises/8-create.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
'use strict';
1+
"use strict";
22

3-
const createUser = null;
3+
const createUser = (name, city) => {
4+
const obj1 = {};
5+
obj1.name = name;
6+
obj1.city = city;
7+
return obj1;
8+
};
49

510
module.exports = { createUser };

Exercises/9-array.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1-
'use strict';
1+
"use strict";
22

3-
const phonebook = null;
3+
const phonebook = [
4+
{ name: "Marcus Aurelius", phone: "+380445554433" },
5+
{ name: "Kate Winslet", phone: "+380502678354" },
6+
{ name: "Robert de Niro", phone: "+380632678354" },
7+
];
48

5-
const findPhoneByName = null;
9+
const findPhoneByName = (name) => {
10+
if (name === name) {
11+
}
12+
for (name of phonebook) {
13+
}
14+
return phone;
15+
};
616

717
module.exports = { phonebook, findPhoneByName };

Exercises/a-hash.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
'use strict';
1+
"use strict";
22

3-
const phonebook = null;
3+
const phonebook = {
4+
marcus: { name: "Marcus Aurelius", phone: "+380445554433" },
5+
kate: { name: "Kate Winslet", phone: "+380502678354" },
6+
robert: { name: "Robert de Niro", phone: "+380632678354" },
7+
};
48

5-
const findPhoneByName = null;
9+
const findPhoneByName = (name) => {
10+
return phone;
11+
};
612

713
module.exports = { phonebook, findPhoneByName };

0 commit comments

Comments
 (0)