const fetchData = new Promise((resolve, reject) => {
    const success = true;
    if (success) {
      resolve("Data received!");
    } else {
      reject("Error fetching data");
    }
});

fetchData
  .then((message) => {
    console.log(message); // Logs "Data received!" after 2 seconds
  })
  .catch((error) => {
    console.log(error); // If rejected, logs "Error fetching data"
  });

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: