Welcome to the Linux Foundation Forum!

Lab 5.1

Hi,
can someone help me with implementing the function prefixer? I'm a bit lost.

  1. 'use strict'
  2. const sayHiTo = prefixer('Hello ')
  3. const sayByeTo = prefixer('Goodbye ')
  4.  
  5.  
  6. function prefixer (str) {
  7. console.log(str);
  8. }
  9.  
  10.  
  11. console.log(sayHiTo('Dave')) // prints 'Hello Dave'
  12. console.log(sayHiTo('Annie')) // prints 'Hello Annie'
  13. console.log(sayByeTo('Dave')) // prints 'Goodbye Dave'
  14.  

Thx a lot

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Comments

    • Return a function from prefixer that accepts an argument
    • concat (e.g. use +) the out str argument and the returned functions argument together
  • The sayHiTo and sayByeTo functions expect a string argument called name. So the prefixer function should return a function that takes a name. As prefixer has it's own argument (greeting) in the outer scope you can use it in the scope of the returned function. Closures are common and confusing :)

  • Posts: 160

    @pamvdam 100%

  • Posts: 2
    edited May 7

    Prefixer function definetion for quick refence could be =

    pass an argument "greeting", -> return an child fuction -> pass an argument "name" -> concate both argument "greeting+''+name" and return.

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Categories

Upcoming Training