push to array help needed
Hi, I'm hoping someone can help.
I'm trying to build a custom interaction with JS but having a few issues, and bare in mind JS is totally new to me so I'm flying blind at the moment.
Basically, what I want is a slide button that will take a user to a random slide from a choice of 5, the result of the random output to be added to an array. User then returns to original slide and proceeds onto another random slide, checking the array to make sure of no duplicates. After the user has visited 3 random unique slides the function will continue onto other actions which I haven't written yet.
Directing users to the random slides is fine, the issue I'm having is that it's not pushing new values to the array, just overwriting them instead. I've not continued with the code yet as I don't see the point until I can get this first bit working properly, but I'll add what I've done below.
Hopefully this made sense, but if not let me know and I'll try to clarify.
var ls_alreadyDone = [];
var num = Math.random();
var game = function() {
if (num <= 0.2) {
rdcmndGotoSlide = 1;
ls_alreadyDone.push(1);
} else if (num > 0.2 && num <= 0.4) {
rdcmndGotoSlide = 2;
ls_alreadyDone.push(2);
} else if (num > 0.4 && num <= 0.6) {
rdcmndGotoSlide = 3;
ls_alreadyDone.push(3);
} else if (num > 0.6 && num <= 0.8) {
rdcmndGotoSlide = 4;
ls_alreadyDone.push(4);
} else if (num > 0.8) {
rdcmndGotoSlide = 5;
ls_alreadyDone.push(5);
}
};
game();
console.log(num);
con
so
(ls_alreadyDone);
