46.0k views
3 votes
Which statement will call a function animate every 50 milliseconds?

1) setInterval(animate, 50)
2) setTimeout(animate, 50)
3) animate(50)
4) requestAnimationFrame(animate)

User Bluephlame
by
8.0k points

1 Answer

2 votes

Final answer:

Option 1) setInterval(animate, 50) is the correct choice to call the 'animate' function every 50 milliseconds.

Step-by-step explanation:

The correct statement to call a function named animate every 50 milliseconds is achieved by using setInterval. So, from the options provided, option 1) setInterval(animate, 50) is the statement that will correctly call the animate function repeatedly every 50 milliseconds until it is stopped. Option 2) setTimeout(animate, 50) will only call the function once after 50 milliseconds. Option 3) animate(50) simply calls the function with 50 as a parameter, but not on a timer. Lastly, option 4) requestAnimationFrame(animate) is used for animations, but it doesn't use a fixed time interval and is instead optimized by the browser for animation tasks.

User Shwaydogg
by
8.6k points