Question
(Javascript) Write a function, `dynamicIntervalCount`, that accepts a callback, a delay in milliseconds, and an optional amount as arguments. The function should set an interval
(Javascript)
Write a function, `dynamicIntervalCount`, that accepts a callback, a delay
in milliseconds, and an optional amount as arguments. The function should
set an interval with the given callback and delay. If an amount argument
is passed, the interval should be cleared after the callback has been
called 'amount' number of times. If an amount argument is not passed,
the interval should not be cleared and `dynamicIntervalCount` should instead
return the Timeout object for the interval.
Examples:
dynamicIntervalCount(function() {
console.log('hi');
}, 500, 3); // prints 'hi' at 500ms intervals a total of 3 times
const timeoutObject = dynamicIntervalCount(function() {
console.log('hi');
}, 500); // prints 'hi' at 500ms intervals indefinitely
console.log(timeoutObject); // Timeout { ... }
***********************************************************************/
function dynamicIntervalCount(cb, delay, amount) {
// Your code here
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started