samedi 3 juillet 2021

Unable to generate and show randomly generated integers

I'm a student and have been attempting to create a program in JavaScript to create a function and generate a random integer (whole number) between 1 and 9. I have created two different programs for this in my testing but while using Visual Studio Code it doesn't print the generated number.

Please see code below and if you have any questions please let me know.

function random_num() {
    let random_num = Math.floor(Math.random() * 9) +1;
    return random_num;
}
console.log(random_num);
function random_num(min, max) {
    min = Math.ceil(1);
    max = Math.floor(9);
    return Math.floor(Math.random() * (max - min)) + min;
}
console.log(random_num);

Thanks in advance!




Aucun commentaire:

Enregistrer un commentaire