I have a small problem. I have an array of 5 winning numbers and a random array draw of 10 numbers between 1 and 26. If all the elements of the winning array are found in the draw array, it should return WIN and LOSE if they aren't. It doesn't work. :(
function bingo(a) {
let draw = [];
let win = [2, 9, 14, 15, 7];
for (let i = 10; i > 0; i--) {
draw.push(Math.floor(Math.random() * 26 + 1));
}
if (win.every((r) => draw.includes(r))) {
return "WIN";
} else {
return "LOSE";
}
}
As I understand from your question, you are just confused because of low probability of matching. You can test it with a constant array to see. However, I see that you are using argument a that does not have any functionality in your function since you define and use just arrays draw and win inside the function
function bingo() {
let draw = [];
let win = [2, 9, 14, 15, 7];
for (let i = 10; i > 0; i--) {
draw.push(Math.floor(Math.random() * 26 + 1));
}
//Here you can change draw with [2, 9, 14, 15, 7] to test
if (win.every((r) => draw.includes(r))) {
console.log(draw);
return "WIN";
} else {
console.log(draw);
return "LOSE";
}
}
bingo();