let gameScope = {}
function generateUniqueNum() {
gameScope.uniqueNumbers = [];
for (let j = 0; j < 4; j++) {
let number = Math.floor((Math.random() * 9)+1);
if (!gameScope.uniqueNumbers.includes(number)) {
gameScope.uniqueNumbers.push(number);
} else {
j--;
}
}
return gameScope.uniqueNumbers;
}
Hey there! I'm new to learning JavaScript and I have an assignment to create a 4 digit array with unique numbers ranging from 1 to 9 (for a game similar to Bulls and Cows). I'm having trouble figuring out how to check this array for repeated numbers. Any help would be greatly appreciated. Thanks!