I am trying to teach myself some JavaScript and play around with recursion at the same time. The code I've written below I expect to print "inhale" to the console 10 times with a 5-second delay in between printing. However when I watch the console in Chrome's dev tools, all entries get printed seemingly instantaneously after refreshing the page. Can anyone help me find the error in my implementation? Thank you!
function breathe(type, counter, limit, duration) {
if(counter <= limit) {
setTimeout(console.log(type), duration);
counter++;
return breathe(type, counter, limit, duration);
}
console.log("Finished!");
}
var breathing = breathe("inhale", 1, 10, 5000);