JSFiddle - React, Tailwind, and code Playground

by Nicolas Pineda

JavaScript

//Performs tasks until negative number is found

var recursiveFunHouse = function(num){
    console.log("Made it here 1");
    var newNum = performSideTasks();
    
    console.log("Made it here 6");
    console.log("newNum");
    console.log(newNum);
    if(newNum-num >0 ){
			recursiveFunHouse(num);
    }
    else{
    	console.log("The FunHouse Generated These Numbers :")
      for(var i = 0; i <numList.length; i++){
      	 console.log(numList[i]);
      }
    }

};

var performSideTasks = function(){
    console.log("Made it here 2");
    someAsyncTask().then(function(num){
			anotherTask(num);
      console.log("made it here 5");
      return num;
		});
    

}

var someAsyncTask = function(){
  return new Promise (function(resolve, reject) {
    console.log("made it here 3");
    var randNum = Math.floor(Math.random()*99) + 1; 
    randNum *= Math.floor(Math.random()*2) == 1 ? 1 : -1;   

    setTimeout(function() { 
      numList.push(randNum)
      resolve(randNum)
    }, 100);
  });
}




var anotherTask = function(num){
  console.log("made it here 4");
	console.log(num);

};

var numList= [];

recursiveFunHouse();