lundi 15 octobre 2018

How to display image related to an array element whenever the element is mouseovered

I have an array of strings. Then I have a function that randomly picks up few of them (getRandom) and displays them. I want to display an image somewhere in DOM when the randomly picked elements are mouseovered/clicked. Do you think this could be possible? Should this be added in getRandom function or somewhere else?

here's my getRandom function:

function getRandom(arr, n) {
    var result = new Array(n),
        len = arr.length,
        taken = new Array(len);
    if (n > len)
        throw new RangeError("getRandom: more elements taken than available");
    while (n--) {
        var x = Math.floor(Math.random() * len);
        result[n] = arr[x in taken ? taken[x] : x];
        taken[x] = --len in taken ? taken[len] : len;
    }
    if (arr == warmUpAll) {
      document.getElementById("warmup").innerHTML = '<span class="exerciseheader">Warm Up - 10 minutes</span>' + "</br>" + result.join(" ");
    }
    else if (arr == legsAll){
      document.getElementById("legsDisplay").innerHTML = '<span class="exerciseheader">Legs</span>' + "</br>" + result.join(" ");
    }
    }
  }

Thank you guys in advance.




Aucun commentaire:

Enregistrer un commentaire