JSFiddle - React, Tailwind, and code Playground

by BurpmanJunior

JavaScript

/**
 * Promise
 */

var _p = new Promise(
	function(resolve, reject){
  	var i = 0;
    
  	var count = function(){
    	var n = Math.floor(Math.random() * 1000);
      //console.log('n: ', n);
      for(i = 0; i < n; i++){
        console.log(i);
      }
    }
    
    var end = function(){
    	if(i % 2 == 0){
      	resolve(i);
      }else{
		    reject(i);
      }
    }
    
    count();
    end();
  }
)

_p.then(
	function(_i){
  	console.log('Then Resolved', _i);
  },
  function(_i){
  	console.log('Then rejected', _i);
  }
).catch(
	function(_i){
  	console.log('Catch Rejected', _i);
  }
)