Can the setInterval method still work when included inside a function? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 11

Can the setInterval method still work when included inside a function?

3rd Apr 2018, 10:50 PM
William Wll Luhanga
William Wll Luhanga - avatar
3 Answers
+ 2
// Actually, you can. You'll just need to call the function to start. function printWhatever() { console.log("whatever"); } function callPrintWhateverEachSecond() { setInterval(printWhatever, 1000); } callPrintWhateverEachSecond(); // Try it out.
5th Apr 2018, 6:35 PM
Maicon Mauricio
Maicon Mauricio - avatar
+ 10
I tried but I was getting a certain error so I dnt know whether it was caused by it or not thus why I asked
4th Apr 2018, 7:54 AM
William Wll Luhanga
William Wll Luhanga - avatar
0
Why not try it in some code?
4th Apr 2018, 1:20 AM
Emma