Reputation: 187
Here is the code which does not work (Nothing is added). The first line will work if I remove the comment. I suppose the variable result is not taking a number or something else. I don't really understand why.
$(document).ready(function ()
//document.getElementById(1).style.display = "inline-block";
// https://www.youtube.com/watch?v=pqLS4oyJ8cA
array.prototype.randsplice = function(){
var rndNumber = Math.floor(Math.random()*this.length);
var lstSplice = this.splice(rndNumber,1);
return lstSplice;
}
var lstNumber = new Array(0,1,2,3,4,5,6,7,8,9);
var result = lstNumber.randsplice();
document.getElementById(result).style.display = "inline-block";
var result = lstNumber.randsplice();
document.getElementById(result).style.display = "inline-block";
var result = lstNumber.randsplice();
document.getElementById(result).style.display = "inline-block";
});
I tried to followed this interesting link: Randomly Empty a Javascript Array but without success. (obviously the style display is originally set to none for all div.)
Any help will be appreciated. Thanks
Upvotes: 1
Views: 151
Reputation: 17868
You're almost there, I noticed 2 mistakes so far;
{
in $(document).ready(function ()
. Which should be $(document).ready(function () {
array.prototype.randsplice
should be Array.prototype.randsplice
And beware that you need jQuery to run this script. And here's the final fiddle
Upvotes: 2