So my problem is I have 2 declared arrays inside a function. Each time I call this function, it removes one item from both arrays. The next time I call the function, the elements is deleted before it remains.
Now I know where the problem is.I know I'm declaring the same arrays in a function call, but what I want is to make those arrays static, and I know if I declared the 2 arrays outside the function it will work out perfectly.
BUT I'm forced to let those arrays declared inside the function. So is there any way I can do this please ? Here's my code:
function Tirage(){
var Binomes=['George','Davide','Anna','Martin','Lucy','Nancy'];
var Projet=['Foundation','Skeleton','Bootstrap','UIkit','Base','W3.CSS'];
var c1=parseInt((Math.random())*(Binomes.length));
var c2=parseInt((Math.random())*(Projet.length));
Binomes.splice(c1,1);
Projet.splice(c2,1);
alert(c1+"\n"+Binomes);
alert(c1+"\n"+Projet);
}
EDIT the initial code is this, and i'm not allowed to change it or have other code outside the function:
function Tirage(){
var Binomes=['George','Davide','Anna','Martin','Lucy','Nancy'];
var Projet=['Foundation','Skeleton','Bootstrap','UIkit','Base','W3.CSS'];
//Complete Code here
}
Edit 2
Seems like the question isn't understandable wich is my fault, so the exercise wants me to create a Randomly Drawing and insert what i draw in rows inside a table. The function that will do this have inside of it 2 decalred Arrays and i have to Draw randomly one element from each array, and insert it as a row with 2 cellules, inside a table.
Because i didn't read the exercise well, i thought that the function only draws once in each function call, meaning that if i click the first time i'll only draw once and insert that draw in the table, then the second time the same thing but with avoiding to draw what is already being inserted in the table.
I'm sorry for that, and the original question is already answer bellow