Jump to content

How do promises program flow work in javascript?


eaglehopes
Go to solution Solved by requinix,

Recommended Posts

"await" is great if you need have all the data before you moving on especially good when developing a game.

// Fetch the First ID
const fetchFirstId = async () => {
    try {
        // fetch the data from the server
        const response = await fetch('get-first-id.php', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify({resetScore: false})
        });

        // parse the response as JSON
        const data = await response.json();
        id = data.first_id; // Grab the First ID the DB Table
        //console.log(id);
        await changeImageSource(data.image);
        await fetchQuestion();
        await fetchWord(); // fetch the answers
        //await fetchImage();
    } catch (error) {
        console.error(error);
    }
};

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.