diff --git a/Exercises/1-let.js b/Exercises/1-let.js index d705443..7c72d28 100644 --- a/Exercises/1-let.js +++ b/Exercises/1-let.js @@ -1,5 +1,5 @@ 'use strict'; -let name = undefined; +let name = 'Roman'; 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..9a6e380 100644 --- a/Exercises/3-hello.js +++ b/Exercises/3-hello.js @@ -1,5 +1,6 @@ 'use strict'; -const hello = null; +const hello = name => console.log(`Hello ${name}!`); +// hello('Roman'); module.exports = { hello }; diff --git a/Exercises/4-range.js b/Exercises/4-range.js index 31bd852..727a113 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++) { + array.push(i); + } + return array; +}; module.exports = { range }; diff --git a/Exercises/5-range-odd.js b/Exercises/5-range-odd.js index 54bb5b4..2e3e1ac 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++) { + (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..da361ef 100644 --- a/Exercises/6-calculate.js +++ b/Exercises/6-calculate.js @@ -1,11 +1,18 @@ '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 = (start = 0, end = 9) => { + const array = []; + for (let i = start; i <= end; i++) { + array.push(average(square(i), cube(i))); + } + return array; +}; -const calculate = null; module.exports = { square, cube, average, calculate }; diff --git a/Exercises/7-objects.js b/Exercises/7-objects.js index 0920026..d081fce 100644 --- a/Exercises/7-objects.js +++ b/Exercises/7-objects.js @@ -1,5 +1,11 @@ 'use strict'; -const fn = null; +const fn = () => { + const object1 = { name: 'Roman' }; + let object2 = { name: 'Serge' }; + object1.name = 'Foma'; + object2.name = 'Alex'; + object2 = { url: 'https://github.com' }; +}; module.exports = { fn }; diff --git a/Exercises/8-create.js b/Exercises/8-create.js index ac27ddd..f400582 100644 --- a/Exercises/8-create.js +++ b/Exercises/8-create.js @@ -1,5 +1,5 @@ 'use strict'; -const createUser = null; +const createUser = (name, city) => ({ name, city }); module.exports = { createUser }; diff --git a/Exercises/9-array.js b/Exercises/9-array.js index 466c69a..2799112 100644 --- a/Exercises/9-array.js +++ b/Exercises/9-array.js @@ -1,7 +1,13 @@ 'use strict'; -const phonebook = null; +const phonebook = [ + { name: 'Marcus Aurelius', phone: '+38044555443' }, + { name: 'Alex', phone: '+91454329566' }, +]; -const findPhoneByName = null; +const findPhoneByName = name => { + for (const person of phonebook) + return person.name === name ? person.phone : null; +}; module.exports = { phonebook, findPhoneByName }; diff --git a/Exercises/a-hash.js b/Exercises/a-hash.js index 466c69a..8d0fc46 100644 --- a/Exercises/a-hash.js +++ b/Exercises/a-hash.js @@ -1,7 +1,10 @@ 'use strict'; -const phonebook = null; +const phonebook = { + marcus: { name: 'Marcus Aurelius', phone: '+380445554433' }, + alex: { name: 'Alex Dobrov', phone: '+914543295661' } +}; -const findPhoneByName = null; +const findPhoneByName = name => phonebook[name].phone; module.exports = { phonebook, findPhoneByName };