<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Advanced custom promise example</title>
  </head>
  <body>
    <script>
      // Define custom promise function

      function timeoutPromise(message, interval) {
        return new Promise((resolve, reject) => {
          if(message === '' || typeof message !== 'string') {
            reject('Message is empty or not a string');
          } else if(interval < 0 || typeof interval !== 'number') {
            reject('Interval is negative or not a number');
          } else {
            setTimeout(function(){
              resolve(message);
            }, interval);
          }
        });
      };

      timeoutPromise('Hello there!', 1000)
      .then(message => {
         alert(message);
      })
      .catch(e => {
        console.log('Error: ' + e);
      });
    </script>
  </body>
</html>
