I have been reworking this a few times and thought this would resolve the issue. I am still getting two of the same numbers though. Also, the array amount will fluctuate from 8 values which I have set the array for, but then go to 9 values which I don't quite understand. Any help would be much appreciated.
function totalQuestion(){
let amountOfQuestionTotal = myObj.length // amount of question
var amountOfQuestionsNeeded = [8];// am
let numberNeeded = 8;
for(var i = 0; i < numberNeeded; i++) {
var countNumber = Math.floor(Math.random() * amountOfQuestionTotal)
var n = amountOfQuestionsNeeded.includes(countNumber)
if (countNumber != n) {
amountOfQuestionsNeeded.push(countNumber);
}
}
return amountOfQuestionsNeeded;
}
totalQuestion();
console.log(totalQuestion());