HYF-Class20 / home

Home repository for HYF Class 20
MIT License
0 stars 2 forks source link

Herbert : Asynchronous Programming: 3 weeks #164

Open HerbertHomolka1 opened 1 year ago

HerbertHomolka1 commented 1 year ago

Asynchronous Programming

Learning Objectives

Week 1

I Need Help With:

nothing

What went well?

Lessons Learned

Week 2

I Need Help With:

I would like to practice a little with other students. Eben has time after class this sunday

What went well?

Lessons Learned

Week 3

I Need Help With:

What went well?

Lessons Learned

bermarte commented 1 year ago

## What went less well?

should produce the following formatted text:

What went less well?

You should be able to see it, it's something you wrote.

sammou00 commented 1 year ago

@HerbertHomolka1 as for the url where to put it , you can put it in your apis function or your data.js as for then

const getUsers = () => {
    return fetch(`https://jsonplaceholder.typicode.com/users`)
        .then((res) => {
            if (!res.ok) {
                throw new Error(
                    `Failed to fetch users with status: ${res.status}`,
                );
            }
            return res.json(); // convert the response to a JavaScript object
        })

        .catch((Error) => {
            console.error(err);
            return null;
        });
};

const needData = (data) => {};

const HandlerUser = () => {
    getUsers().then((data) => {
        console.log(data); // you will get here what ever the first then return so in this case data
        // here you can do whatever you want with your data , you can loop throw them because they are an array in this case
        // you can pass them to another function if you want to
        needData(data);
    });
};

HandlerUser();

there are a lot of examples on my gitHub account check them.