Leaderboard Archive
Javascript May 3, 2026

Spot the bug: This should only run the callback once after 1 second.

function delay(ms, callback) {
  setInterval(callback, ms)
}
delay(1000, () => console.log("done"))
A The arrow function is wrong
B setInterval repeats forever — use setTimeout instead
C ms should be in seconds not milliseconds
D callback needs parentheses
Explanation
setInterval keeps calling the function over and over every ms milliseconds until you stop it. setTimeout runs the function just once after the delay. Easy trick to remember: Interval = repeats (like an interval in sports), Timeout = runs once after a delay.
📝
Reviewed by CodeShot Editorial
Every challenge is code-reviewed by senior developers to ensure accuracy and real-world relevance. Learn more.

Ready for your shot?

Join thousands of developers solving one logic puzzle every morning.

Solve Today's Challenge →