0

I began playing with js and I'm currently stuck with a problem I can't resolve by myself:

Here below is a small part of the code I have, I wait for a bot to start, then execute a function every minute. The problem I face is with the save of the data, indeed d always keep the value 0 and never get set to the json object I have as "data".

I am pretty new to js, please take it easy :)


var d = 0;

function bazar() {
    fetch('https://api.hypixel.net/skyblock/bazaar')
        .then(response => response.json())
        .then(data => d = data);
    setTimeout(() => bazar(), 60000);
}

client.on("ready", () =>
{
    bazar();
    console.debug(JSON.stringify(d));
});
Ren
  • 157
  • 12
  • 1
    That's because you don't wait for `bazar()` to finish. Your console.log line runs long before `bazar()` finishes. – Andy Ray Sep 16 '22 at 23:11
  • Actually it's doing it but your console.log() doesnt wait for it , if u and one more then and console.log(d) inside of it u will see it changes – Rahman Aliyev Sep 16 '22 at 23:51

0 Answers0