settimeout()

This page writes output to the console

The first loop just traverses a list of numbers

The second loop creates an array and traverses it

A global var is declared for the array of URLs - it should be visable outside the block it was declared (in fact it is not in a block)

The syntax for settimeout() - the first parameter is the function to be called and the second is the time that this is delayed. The setTimeout() is only called once.

The W3C documentation does say that if you want the function to repeat then you should use setInterval(). I tried this but it seems that it just echoed the contents of the arrar in an endless loop.

Top

It would seem that the original code for the slideshow was smarter than I thought. The use of setTimeout is used within a loop that never terminates as the index is reset when the length of the image array is reached. The call to setTimeout calls the carousel() to execute only once after a timeout. From here all the images are hidden and the next image is displayed.

Links

Link to PDF Disabled

If you require a copy please email tempusfugit.me.uk

Top

References -

  • 1 - Window setTimeout() - https:// www.w3schools.com/jsref/ met_win_settimeout.asp