Apostolos once again, the first argument in setTimeout
is not a function, it's the return value of printLog
. In your case it's undefined.
Here's how it could work
export const delayedLog = (s, n) => {
const printLog = (str) => () => {
console.log(str);
}
setTimeout(printLog(s), n * 1000);
}
This way printLog
returns a function, that setTimeout will can when necessary.
Once you understand the change, you can simplify the code:
export const delayedLog = (s, n) => {
setTimeout(() => console.log(s), n * 1000);
}
Don't move forward until you understand what exactly went wrong in your code.