Creating a raffle draw module

Hi everyone ! I am creating a code for a raffle draw module based on a list of winners, however it seems like I am stucked and can’t find where is my issue…

For information, when I run the code, the console returns entier as undefined.

Here is the code :

import wixData from 'wix-data';
var entier
var max1

export function button11_click(event) {     //trigger the module on click
    $w('#dataset1').setFilter(wixData.filter() 
 
    .contains("nomDuMatch", $w("#input7").value)
    .eq("scoreDuPremier", $w("#dropdown1").value)
    .eq("scoreDuSecond", $w("#dropdown2").value)
    ) //filter the dataset to only keep the correct answers

    max1 = $w("#dataset1").getTotalCount(); //set the max value of the range in which the random number will be drawn
    console.log(max1) 
    
    Choix_nombre(); //randomly define the value of entier
    console.log(entier)
    
    last(); //use entier to only show the person that have been drawn
    $w('#repeater1').expand();
}

function Hasard (min, max) {
 return Math.floor(Math.random() * (max - min + 1)) + min;
}

function Choix_nombre () {
    setInterval(function () {
        entier = Hasard(1, max1);
        Hasard();
    })
}

function last () {
    $w("#dataset1").setCurrentItemIndex(entier);
}

If anyone would have any idea to debug, that would be awesome !

Thank you !

You don’t have an interval specified on the setInterval() function and I believe that it will not execute. Also, I don’t understand why, but you call Hasard() twice, with the second time not using any parameters and not returning any value.