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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!