JavaScript: Помощь при вызове возвращаемой функции и добавлении в строку каждый раз, когда вызывается возвращаемая функция - PullRequest
0 голосов
/ 16 октября 2019

Я застрял в решении нижеприведенной проблемы. Я все еще относительно новичок в JS, и меня сбивают с толку, какая из функций, первая или возвращенная, должна вызываться каждый раз, и как утверждать, что это альтернативный вызов. Кроме того, мне нужна переменная count?

The problem asks to write a function called alternate, that returns another function. Should add the string 'hey' to a message every other time the returned function is called 
ie: 
`returnedFunc()`; message = 'hey' (1st invocation)
`returnedFunc()`; message = 'hey' (2nd invocation)
 message = 'heyhey' (3rd invocation)
 message = 'heyhey' (4th invocation) ....


this is what I have so far: 

const alternate = () => {
    let message; 
    let count = 0; 
    return function sayHey(){
        count++; 
            if(count % 2 !== 0){
                message += 'hey'; 
            } else{
                alternate(); 
            }
            return message; 
    };
};
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...