javascript - How to Change Element Text on Mouse Click -


so, i'm new kind of stuff, , have question. found code picking random word, not picking again until word have been picked.

function shuffle(array) {   var m = array.length, t, i;   while (m > 0)    {     = math.floor(math.random() * m--);     t = array[m];     array[m] = array[i];     array[i] = t;   }   return array; }  var keywords = ["cheese", "apples", "grapes", "chicken", "potatoes", "beef", "bananas"];  shuffle(keywords); // shuffles array  alert(keywords); 

and brought question. how can trigger when white box, posing card, has been clicked? box display 1 of values @ 1 time, , randomly pick word when clicked, using code.

any super appreciated.

there no need use shuffle, can pick random item using like

var keywords = ["cheese", "apples", "grapes", "chicken", "potatoes", "beef", "bananas"];    var mybox = document.getelementbyid('mybox'),    idx;  //click handler box  mybox.addeventlistener('click', function() {    var index;    {      index = math.floor(math.random() * keywords.length);    } while (index == idx); //to make sure every click changes selcted value    mybox.innerhtml = keywords[index];    idx = index;  })
#mybox {    border: 1px solid black;    height: 100px;    width: 100px;    text-align: center;  }
<div id="mybox"></div>


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -