diff --git a/Exercises/1-let.js b/Exercises/1-let.js index d705443..e1e92f5 100644 --- a/Exercises/1-let.js +++ b/Exercises/1-let.js @@ -1,5 +1,5 @@ 'use strict'; -let name = undefined; +let name = 'Mykhailo'; module.exports = { name }; diff --git a/Exercises/2-const.js b/Exercises/2-const.js index 5512738..3202210 100644 --- a/Exercises/2-const.js +++ b/Exercises/2-const.js @@ -1,5 +1,5 @@ 'use strict'; -const year = undefined; +const year = 2003; module.exports = { year }; diff --git a/Exercises/3-hello.js b/Exercises/3-hello.js index a597391..091a6e5 100644 --- a/Exercises/3-hello.js +++ b/Exercises/3-hello.js @@ -1,5 +1,9 @@ 'use strict'; -const hello = null; + +const hello = (name) => { + console.log(`Hello, ${name}!`); +}; + module.exports = { hello }; diff --git a/Exercises/4-range.js b/Exercises/4-range.js index 31bd852..0e95888 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 result = []; + for (let i = start; i <= end; i++) { + result.push(i); + } + return result; +}; module.exports = { range }; diff --git a/Exercises/5-range-odd.js b/Exercises/5-range-odd.js index 54bb5b4..159a651 100644 --- a/Exercises/5-range-odd.js +++ b/Exercises/5-range-odd.js @@ -1,5 +1,14 @@ 'use strict'; -const rangeOdd = null; +const rangeOdd = (start, end) => { + const result = []; + for (let i = start; i <= end; i++) { + if (i % 2 !== 0) { + result.push(i); + } + } + return result; +}; + module.exports = { rangeOdd }; diff --git a/Exercises/6-calculate.js b/Exercises/6-calculate.js index dfecf6b..9aaa961 100644 --- a/Exercises/6-calculate.js +++ b/Exercises/6-calculate.js @@ -1,11 +1,23 @@ 'use strict'; -const square = null; +const square = (x) => { + return x * x; +}; -const cube = null; +const cube = (x) => { + return x * x * x; +}; -const average = null; +const average = (a, b) => { + return (a + b) / 2; +}; -const calculate = null; +const calculate = () => { + const results = []; + for (let i = 0; i <= 9; i++) { + results.push(average(square(i), cube(i))); + } + return results; +}; module.exports = { square, cube, average, calculate }; diff --git a/Exercises/7-objects.js b/Exercises/7-objects.js index 0920026..a103629 100644 --- a/Exercises/7-objects.js +++ b/Exercises/7-objects.js @@ -1,5 +1,20 @@ 'use strict'; -const fn = null; +const fn = () => { + const objConst = { name: 'Constant Object//' }; + + let objVar = { name: 'Variable Object' }; + + objConst.name = 'New Constant Object'; + objVar.name = 'New Variable Object'; + + + + objVar = { name: 'Another Variable Object' }; + + + console.log(objConst); + console.log(objVar); + }; module.exports = { fn }; diff --git a/Exercises/8-create.js b/Exercises/8-create.js index ac27ddd..d7754b2 100644 --- a/Exercises/8-create.js +++ b/Exercises/8-create.js @@ -1,5 +1,7 @@ 'use strict'; -const createUser = null; +const createUser = (name, city) => { + return { name, city }; +}; module.exports = { createUser }; diff --git a/Exercises/9-array.js b/Exercises/9-array.js index 466c69a..2641021 100644 --- a/Exercises/9-array.js +++ b/Exercises/9-array.js @@ -1,7 +1,18 @@ 'use strict'; -const phonebook = null; +const phonebook = [ + { name: 'Marcus Aurelius', phone: '+380445554433' }, + { name: 'Mykhailo Chubko', phone: '+38055554434' }, + { name: 'Ksenii Mizina', phone: '+380555554435' } +]; -const findPhoneByName = null; +const findPhoneByName = (name) => { + for (const entry of phonebook) { + if (entry.name === name) { + return entry.phone; + } + } + return null; +}; module.exports = { phonebook, findPhoneByName };