Last Updated: February 25, 2016
· willrax

setInterval with Coffeescript

This will run the setInterval function every 2 secs. It grabs a random word from the array and replaces the text in the phrase span with it.

$(document).ready ->
    setInterval () ->
        a = ['WOOHOO!', 'YAY!', 'HOORAY!']
        w = a[Math.floor(Math.random()*a.length)];
    , 2000

1 Response
Add your response


How to pass some parameter to this function?

(for ex., I have variable @myWindow upper from the setInterval code and wanna to output every 5 seconds @myWindow.location.href; )

over 1 year ago ·