Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


                <!-- hidden is a semantic attribute to hide elements -->
<!-- having a number input adds more security that the value will always be a number -->
<input id="js-imageSource-index" type="number" value="0" hidden/>
<!-- <button onclick="loopPoses()">Loop</button> -->
<!-- Adding js- is a great way to seprate js related ID's or classes  -->
<button id="js-slide-trigger">Loop</button>
<img id="js-slide" width="300" height="300" src=""/>





                // don't use global variables that are mutable this will make 
// code harder to comprehensive i.e. the code can go in multiple 
// directions if the value can be changed by anyone
// var i = 0;          // Start Point
var imageElem = document.getElementById('js-slide')
var triggerElem = document.getElementById("js-slide-trigger")
var ImagesIndexElem = document.getElementById('js-imageSource-index')
var imageSources = [

// This will tell javascript to wait
// don't worry about how it works if you aren't familiar with promises yet
// see: for more on Promises
// P.S. I just copy pasted this from google.
const wait = (amount = 0) => new Promise(resolve => setTimeout(resolve, amount));

async function slideShow(){
//   1. If you read this value outside function this will can be changed in 
//      view but javascript variable will not be changed so it will get stale
//   2. Cast the value to Number  
  /* 1 */
  const topIndex = /* 2 */ Number(ImagesIndexElem.value)
//  This will only work if index is below images length 
  if (topIndex < imageSources.length) {
    const imagesOfThisIndex = imageSources[topIndex]
    for (var middleIndex = 0; middleIndex < imagesOfThisIndex.length; middleIndex++) {
//       wait (in milliseconds)
      await wait(1000)
      imageElem.src = imagesOfThisIndex[middleIndex]
//     after slideshow is completed increase the topIndex
    ImagesIndexElem.value = topIndex + 1

triggerElem.addEventListener('click', slideShow)