You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30-Days-Of-JavaScript/Exercise-Solutions/days/11_day_des_spreading.md

2.9 KiB

Day 11 - Destruction And Spreading

Exercise:Solutions

Home | << Day 10 | Day 12 >>

Exercise Solutions

Exercises Level 1

  1. Destructure and assign the elements of constants array to e, pi, gravity, humanBodyTemp, waterBoilingTemp.
//app.js
const constants = [2.72, 3.14, 9.81, 37.5, 100]
const [E,PI,G,humanBodyTemp,waterBoilingTemp] =constants
console.log(E,PI,G,humanBodyTemp,waterBoilingTemp)

  1. Destructure and assign the elements of countries array to fin, est, sw, den, nor
//app.js
const countries =['Finland','Estonia','Sweden','Denmark','Norway']
const [fin,est,swd,den,nor] = countries
console.log(fin,est,swd,den,nor)

  1. Destructure the rectangle object by its properties or keys.
//app.js
const rectangle ={
    width:20,
    height:10,
    are:200,
    perimeter:60
}

const {width,height,are,perimeter} = rectangle
console.log(width,height,are,perimeter)


Exercises Level 2

  1. Iterate through the users array and get all the keys of the object using destructuring
//app.js
const users = [
    {
      name:'Brook',
      scores:75,
      skills:['HTM', 'CSS', 'JS'],
      age:16
    },
    {
      name:'Alex',
      scores:80,
      skills:['HTM', 'CSS', 'JS'],
      age:18
    },
    {
      name:'David',
      scores:75,
      skills:['HTM', 'CSS'],
      age:22
    },
    {
      name:'John',
      scores:85,
      skills:['HTML'],
      age:25
    },
    {
      name:'Sara',
      scores:95,
      skills:['HTM', 'CSS', 'JS'],
      age: 26
    },
    {
      name:'Martha',
      scores:80,
      skills:['HTM', 'CSS', 'JS'],
      age:18
    },
    {
      name:'Thomas',
      scores:90,
      skills:['HTM', 'CSS', 'JS'],
      age:20
    }
    ]
    for( const {name,scores,skills,age} of users){
           console.log(name,scores,skills,age)
    }

  1. Find the persons who have less than two skills
//app.js

const users = [
{
  name:'Brook',
  scores:75,
  skills:['HTM', 'CSS', 'JS'],
  age:16
},
{
  name:'Alex',
  scores:80,
  skills:['HTM', 'CSS', 'JS'],
  age:18
},
{
  name:'David',
  scores:75,
  skills:['HTM', 'CSS'],
  age:22
},
{
  name:'John',
  scores:85,
  skills:['HTML'],
  age:25
},
{
  name:'Sara',
  scores:95,
  skills:['HTM', 'CSS', 'JS'],
  age: 26
},
{
  name:'Martha',
  scores:80,
  skills:['HTM', 'CSS', 'JS'],
  age:18
},
{
  name:'Thomas',
  scores:90,
  skills:['HTM', 'CSS', 'JS'],
  age:20
}
]
let a = users.forEach((element) => {
    if(element.skills.length <=2){
        console.log(element)
    }
})

Exercises Level 3

Home | << Day 10 | Day 12 >>