diff --git a/Exercises/1-let.js b/Exercises/1-let.js index d705443..ab3f287 100644 --- a/Exercises/1-let.js +++ b/Exercises/1-let.js @@ -1,5 +1,5 @@ 'use strict'; -let name = undefined; +let name = 'Urich'; module.exports = { name }; diff --git a/Exercises/2-const.js b/Exercises/2-const.js index 5512738..1dedd16 100644 --- a/Exercises/2-const.js +++ b/Exercises/2-const.js @@ -1,5 +1,5 @@ 'use strict'; -const year = undefined; +const year = 1984; module.exports = { year }; diff --git a/Exercises/3-hello.js b/Exercises/3-hello.js index a597391..ef846d3 100644 --- a/Exercises/3-hello.js +++ b/Exercises/3-hello.js @@ -1,5 +1,7 @@ 'use strict'; -const hello = null; +const hello = name => { + console.log(`Welcome home, ${name}`); +}; module.exports = { hello }; diff --git a/Exercises/4-range.js b/Exercises/4-range.js index 31bd852..8d5d30f 100644 --- a/Exercises/4-range.js +++ b/Exercises/4-range.js @@ -1,5 +1,11 @@ 'use strict'; -const range = null; +const range = (start, end) => { + const array = []; + for (let i = start; i <= end; i += 1) { + array.push(i); + } + return array; +}; module.exports = { range }; diff --git a/Exercises/5-range-odd.js b/Exercises/5-range-odd.js index 54bb5b4..2b00871 100644 --- a/Exercises/5-range-odd.js +++ b/Exercises/5-range-odd.js @@ -1,5 +1,11 @@ 'use strict'; -const rangeOdd = null; +const rangeOdd = (start, end) => { + const array = []; + for (let i = start; i <= end; i += 1) { + if (i % 2 !== 0) array.push(i); + } + return array; +}; module.exports = { rangeOdd }; diff --git a/Exercises/6-calculate.js b/Exercises/6-calculate.js index dfecf6b..9e85651 100644 --- a/Exercises/6-calculate.js +++ b/Exercises/6-calculate.js @@ -1,11 +1,17 @@ 'use strict'; -const square = null; +const square = x => x * x; -const cube = null; +const cube = x => x ** 3; -const average = null; +const average = (a, b) => (a + b) / 2; -const calculate = null; +const calculate = () => { + const array = []; + for (let i = 0; i < 10; i += 1) { + array.push(average(square(i), cube(i))); + } + return array; +}; module.exports = { square, cube, average, calculate }; diff --git a/Exercises/7-objects.js b/Exercises/7-objects.js index 0920026..cd311f9 100644 --- a/Exercises/7-objects.js +++ b/Exercises/7-objects.js @@ -1,5 +1,14 @@ 'use strict'; -const fn = null; +const fn = () => { + const obj1 = { name: 'Jmih' }; + let obj2 = { name: 'Urich' }; + const obj3 = { mask: 'NT-200' }; + + obj1.name = 'Shpack'; + obj2.name = 'Seryoja'; + //obj1 = obj3; //obj1 assigned as a constant + obj2 = obj3; +}; module.exports = { fn }; diff --git a/Exercises/8-create.js b/Exercises/8-create.js index ac27ddd..52d3503 100644 --- a/Exercises/8-create.js +++ b/Exercises/8-create.js @@ -1,5 +1,8 @@ 'use strict'; -const createUser = null; +const createUser = (name, city) => { + const user = { name, city }; + return user; +}; module.exports = { createUser }; diff --git a/Exercises/9-array.js b/Exercises/9-array.js index 466c69a..e0e9bb8 100644 --- a/Exercises/9-array.js +++ b/Exercises/9-array.js @@ -1,7 +1,17 @@ 'use strict'; -const phonebook = null; +const phonebook = [ + { name: 'Marcus', phone: '+380445554433' }, + { name: 'Valeriy', phone: '+380982285427' }, + { name: 'Denis', phone: '+380665527456' }, +]; -const findPhoneByName = null; +const findPhoneByName = n => { + for (const i of phonebook) { + if (i.name === n) { + return i.phone; + } + } +}; module.exports = { phonebook, findPhoneByName }; diff --git a/Exercises/a-hash.js b/Exercises/a-hash.js index 466c69a..da39bf6 100644 --- a/Exercises/a-hash.js +++ b/Exercises/a-hash.js @@ -1,7 +1,13 @@ 'use strict'; -const phonebook = null; +const phonebook = { + Jmih: { phone: '+380982285427' }, + Urich: { phone: '+380661488228' }, + Denis: { phone: '+380445422827' }, + Shpack: { phone: '+380541488273' }, + Sanya: { phone: '+380965042075' } +}; -const findPhoneByName = null; +const findPhoneByName = name => phonebook[name].phone; module.exports = { phonebook, findPhoneByName };