Golf Trivia Game

I’m creating a text based golf game. I’m using a Wix collection to pass questions to a text element and answers to button elements. I’m filtering 9 or 18 questions, based on user input and creating an array with the selected number of questions/answers. Everything works until I try to move the question/answers to the output/input elements. I suspect that there is an issue in the loadQuestion function.

async function loadQuestions ( numHoles ) {
try {
const results = await wixData . query ( “GolfTrivia” )
. ascending ( “triviaQuestion” )
. find ();
questions = shuffleArray ( results.items );
questions = selectRandomItems ( questions , numHoles );
loadQuestion ();
$w ( “#answer1Button” ). enable ();
$w ( “#answer2Button” ). enable ();
$w ( “#answer3Button” ). enable ();
$w ( “#answer4Button” ). enable ();
$w ( “#nextHoleButton” ). disable ();
} catch ( err ) {
console . error ( “Collection Load Failed” , err );
}
}

function loadQuestion () {
currentQuestion = questions . find ( q => q.hole === currentHole );
if (! currentQuestion ) {
return ;
}
$w ( “#triviaQuestion” ). text = currentQuestion.triviaQuestion ;
$w ( “#answer1Button” ). label = currentQuestion.answer1 ;
$w ( “#answer2Button” ). label = currentQuestion.answer2 ;
$w ( “#answer3Button” ). label = currentQuestion.answer3 ;
$w ( “#answer4Button” ). label = currentQuestion.answer4 ;
$w ( “#narrative” ). text = currentQuestion.narrative || “No Narrative Available” ;
}

As a novice (this is my first ever project), I’d appreciate any help that is offered. Thank you.