Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you really wanted to make sure an image is never repeated until all of them have been shown, you can store a list of indices you have already displayed using <code>localstorage</code>.</p> <p>You can use </p> <pre><code>localStorage['viewedItems'] = JSON.stringify(viewedItems) </code></pre> <p>to save an array to <code>localstorage</code>, where viewedItems (the second one) is the name of the array containing all of the indices you have already shown. You can then use </p> <pre><code>JSON.parse(localStorage['viewedItems']) </code></pre> <p>to retrieve the array on every page load to see what you've already displayed. Every time, you're reading it, adding an index (pick an index until you get one not in this array), writing it. Once the size of the array has reached the number of images you have, clear it and start over.</p> <p><strong>Updated, and hopefully more detailed, explanation</strong></p> <p>First you want to load the <code>viewedItems</code> array from <code>localStorage</code>. Then pick a random number as you already do, and see if that number exists in <code>viewedItems</code>. You can do this using <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf" rel="nofollow">indexOf</a>. The select a number and check if exists code will be in a loop so you keep doing it until you find a number that doesn't exist in your array. Show that index. You can then use the <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/push" rel="nofollow">push</a> method to add this index to your <code>viewedItems</code> array. Finally, save the <code>viewedItems</code> array to <code>localStorage</code>.</p> <p><strong>Pseudocode</strong></p> <pre><code>load viewedItems from localStorage do r = random number while viewedItems.indexOf(r) &gt; -1 show xoxo[r] viewedItems.push(r) save viewedItems to localStorage </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload