javascript - NBA Draft Lottery remove array item after it is revealed upon button click -


https://jsfiddle.net/7jux5rlx/3/?

full code above

i'm trying make random nba draft lottery 8 teams (using array 8 images) reveals image of team 8th pick on button click , removes array list leaving 7 remaining teams , on. i dont want remove image, item option array when click following 7 buttons. trying use 8 list images in array, , 8 buttons numbered 1-8. want similar nba's draft lottery if has code formula percentages great.

the odds each team chances 1st pick = 25%, 2nd pick 16.4%, 3rd pick 16.4%, 4th pick 16.3%, 5th pick 9.4%, 6th pick 6.6%, 7th pick 4.4%, 8th pick 2.7%, here have now. can't seem button reveal random team. fantasy league not professional site or anything.

function teams() {   var ateams = [];   ateams[0] = "<img src='http://i.imgur.com/kowpajr.png' height='100' width='100' alt='cavs'>";    ateams[1] = "<img src='http://i.imgur.com/kowpajr.png' height='100' width='100' alt='suns'>";    ateams[2] = "<img src='http://i.imgur.com/kowpajr.png' height='100' width='100' alt='rockets'>";    ateams[3] = "<img src='http://i.imgur.com/kowpajr.png' height='100' width='100' alt='nuggets'>";    ateams[4] = "<img src='http://i.imgur.com/kowpajr.png' height='100' width='100' alt='celtics'>";    ateams[5] = "<img src='http://i.imgur.com/kowpajr.png' height='100' width='100' alt='raptors'>";    ateams[6] = "<img src='http://i.imgur.com/kowpajr.png' height='100' width='100' alt='thunder'>";    ateams[7] = "<img src='http://i.imgur.com/kowpajr.png' height='100' width='100' alt='warriors'>";   var rdmteams = math.floor(math.random() * ateams.length);   document.getelementbyid("table").value = ateams[rdmteams]; } 

https://jsfiddle.net/7jux5rlx/4/

this no means perfect. needs formatting of code, asked believe. there html need on fiddle.

/* * create listener button click */ var table = document.getelementbyid("table"); table.addeventlistener('click', function(event) {     if (event.target.nodename == "button") {         // div corresponding button clicked         var thispickdiv = document.getelementbyid(event.target.id.replace("btn", "div"));         var rdmnum = math.floor(math.random() * ateams.length);         thispickdiv.innerhtml = ateams[rdmnum];         ateams.splice(rdmnum, 1);     } }); 

the image stays on page. hope meant not removing image. if not can done having 2 arrays (one teams , other img sources) not know benefit afford you.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

c++ - Clear the memory after returning a vector in a function -

erlang - Saving a digraph to mnesia is hindered because of its side-effects -