Tuesday 23 May 2017

Best way to add timings between functions?

Okay, so I've been doing some JS practice and I decided to make a basketball simulation in console. The main issue for me is making a timings between functions:

function aball() {
    rng = Math.random()*100;
    if (rng > 50) {
        Ascore + 2;
        console.log('Team A scored 2 points!');
        bball();
    } else {
        console.log('Team A missed!');
        rng = Math.random()*100;
        if (rng > 50) {
            aball();
            console.log('Team A rebounded!');
        } else {
            bball();
            console.log('Team B got the rebound!');
        }
    }
}

Here is team A function. I want to make 5 second timing between each call of the function. There is also a bball function for the other team.



via Petras Vilkelis

No comments:

Post a Comment