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/19_day_clouse.md

1.5 KiB

Day 19 - Closures

Exercise:Solutions

Home | << Day 18 | Day 20 >>

Exercise Solutions

Exercises: Level 1

  1. Create a closure which has one inner function
// app.js
function myFunction(){
  let firstName ="Nevzat"
  let lastName = "Atalay"
  
  function innerFunction(){
   return console.log(firstName,lastName)
  }
  return innerFunction
}

const innerFun = myFunction()

innerFun()

Exercises: Level 2

  1. Create a closure which has three inner functions
// app.js

function myFunction(){
  let a =5
  let b = 7
  
  function total(){
   return a + b 
  }
  function extraction(){
    return a - b
  }
  function multiply(){
    return a * b 
  }

  return{
    total:total(),
    extraction:extraction(),
    multiply:multiply()
  }

  
}

const innerFun = myFunction()

console.log(innerFun.total)
console.log(innerFun.extraction)
console.log(innerFun.multiply)

Exercises: Level 3

  1. Create a personAccount out function. It has firstname, lastname, incomes, expenses inner variables. It has totalIncome, totalExpense, accountInfo,addIncome, addExpense and accountBalance inner functions. Incomes is a set of incomes and its description and expenses is also a set of expenses and its description.

Home | << Day 18 | Day 20 >>