I read about a loot box system and wanted to make my own kind of lucky number calculator.
I have 2 arrays, one with regular numbers and one with the winning ones. Two numbers will be put in a variable and if both these numbers are in the winning array you win!
Now the thing i'm struggling with is that when i make the numbers random my if else statement doesn't work anymore. It will always say false even though the numbers are correct.
if you declare the variables not random, it does work ( it is shown in the code below).
How can i make the if else statement working with the random generator?
CODE:
function go(){
var Numbers = ['one', 'two', 'three','four','five'];
var LuckyNumbers = ['three', 'four', 'seven']
var num1, num2;
num1 = Numbers.splice(Math.floor(Math.random() * Numbers.length), 1);//This doesnt work..
num2 = Numbers.splice(Math.floor(Math.random() * Numbers.length), 1);//This doesnt work..
// num1 ="three"; -> this works but it is not random
// num2 ="four"; -> this works but it is not random
if([num1, num2].every(item => LuckyNumbers.includes(item))) { //always false when using the randoms.
console.log("yep")
} else{
console.log('nope')
}
}
'one'instead of numbers1?