From 9207ca623027da65719e01ad312525baf1b9471f Mon Sep 17 00:00:00 2001 From: Fitsumhelina Date: Thu, 28 Nov 2024 13:49:38 +0300 Subject: [PATCH] fuction exercise one 100% commplated --- Exercises/day-1/function-exercise-1.js | 34 ++++++++++++++++++++++++++ Exercises/test/test.js | 16 ++++-------- 2 files changed, 39 insertions(+), 11 deletions(-) create mode 100644 Exercises/day-1/function-exercise-1.js diff --git a/Exercises/day-1/function-exercise-1.js b/Exercises/day-1/function-exercise-1.js new file mode 100644 index 0000000..6122c0e --- /dev/null +++ b/Exercises/day-1/function-exercise-1.js @@ -0,0 +1,34 @@ +// Create a function called getPersonInfo. The getPersonInfo function takes an object parameter. +// The structure of the object and the output of the function is given below. Try to use both a regular way and destructuring +// and compare the cleanness of the code. If you want to compare your solution with my solution, check this link. + +const person = { + firstName: 'Asabeneh', + lastName: 'Yetayeh', + age: 250, + country: 'Finland', + job: 'Instructor and Developer', + skills: [ + 'HTML', + 'CSS', + 'JavaScript', + 'React', + 'Redux', + 'Node', + 'MongoDB', + 'Python', + 'D3.js', + ], + languages: ['Amharic', 'English', 'Suomi(Finnish)'], +} + +const getPersonInfo = (person) => { + const {firstName, lastName, age, country, job, skills, languages} = person; + const {skill1,skill2,skill3,skill4,skill5,skill6,skill7,skill8,skill9} = skills; + console.log(`${firstName} ${lastName} lives in ${country}. He is ${age} years old. He is an ${job}. He teaches ${skill1}, ${skill2}, ${skill3}, ${skill4}, ${skill5}, ${skill6}, ${skill7}, ${skill8}, ${skill9}. He speaks ${languages[0]}, ${languages[1]} and a little bit of ${languages[2]}`); +} + +getPersonInfo(person) +/* +Asabeneh Yetayeh lives in Finland. He is 250 years old. He is an Instructor and Developer. He teaches HTML, CSS, JavaScript, React, Redux, Node, MongoDB, Python and D3.js. He speaks Amharic, English and a little bit of Suomi(Finnish) +*/ \ No newline at end of file diff --git a/Exercises/test/test.js b/Exercises/test/test.js index 3960126..ab52d3a 100644 --- a/Exercises/test/test.js +++ b/Exercises/test/test.js @@ -1,13 +1,7 @@ -arr=[1,2,3,4,5] - - -const squre = () => { - const result =[] - arr.forEach(element => { - result.push( element*2 ) - - }); - return result +const rectangle = { + width: 20, + height: 10, } -console.log(squre()) \ No newline at end of file +let { width, height, perimeter = 200 } = rectangle +console.log(width, height, perimeter) \ No newline at end of file