Search code examples
javascriptfunctioncallbackargumentsinline

how to pass the functions with args in an inline function in JS?


function emotions(myString, myFunc) {
    console.log("I am " + myString + ", " + myFunc(2));
}

// your code goes here
// call the emotions function here and pass in an
 var laugh = function(max){
    var str ="";
    for(var i=0; i<max ;i++){
        str += "ha";
    }
    return str+"!";
};

// inline function expression
emotions("happy", laugh(2));

can anyone revert me , where I made a mistake? Thanks to all in advance


Solution

  • The emotions function accepts 2 arguments- 1. myString - which is a string 2. myFunc - which is a function

    The laugh function returns a string. laugh(2) => haha!

    Hence, you should just pass laugh as a parameter to emotions as follows emotions("happy", laugh)