Welcome to the Linux Foundation Forum!

Lab 5.1

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

'use strict'
const sayHiTo = prefixer('Hello ')
const sayByeTo = prefixer('Goodbye ')


function prefixer (str) {
    console.log(str);
    }


console.log(sayHiTo('Dave')) // prints 'Hello Dave'
console.log(sayHiTo('Annie')) // prints 'Hello Annie'
console.log(sayByeTo('Dave')) // prints 'Goodbye Dave'

Thx a lot

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 :)

  • xdxmxc
    xdxmxc Posts: 110

    @pamvdam 100%

Categories

Upcoming Training