Advertisement
fakhrycodepolitan

app.js

Sep 20th, 2024
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 0.67 KB | Source Code | 0 0
  1. const warnaBerubah = async (color, gagal, berhasil) => {
  2.   const delay = Math.floor(Math.random() * 4000) + 500;
  3.   console.log(delay);
  4.   setTimeout(() => {
  5.         if (delay > 3000) {
  6.           gagal('gagal');
  7.         } else {
  8.           document.body.style.backgroundColor = color;
  9.           berhasil('berhasil');
  10.         }
  11.       }, delay,
  12.   );
  13. };
  14. const perubahan = async () => {
  15.  
  16.   const gagal = (errorMessage) => {
  17.     console.log(errorMessage);
  18.   };
  19.  
  20.   const berhasil = (successMessage) => {
  21.     console.log(successMessage);
  22.   };
  23.  
  24.   try {
  25.     await warnaBerubah('blue', gagal, berhasil);
  26.   } catch (sa) {
  27.     console.log(sa);
  28.   }
  29.  
  30. };
  31.  
  32. perubahan();
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement