This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The son will climb the tree and check the weather | |
const sonChecksWeather = () => { | |
const possibleOutcome = ["Sunny","Rainy","Unexpected error"] | |
setTimeout(()=>{ | |
const randomNumber = Math.floor(Math.random()*2); | |
const result = possibleOutcome[randomNumber]; | |
console.log("Son: The weather is ", result) | |
// the father will decide | |
fatherWillDecide(result) | |
},2000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sonChecksWeather = new Promise(function (resolve, reject) { | |
setTimeout(() => { | |
const possibleOutcome = ['Sunny', 'Rainy', 'Unexpected error'] | |
const randomNumber = Math.floor(Math.random() * 2) | |
const result = possibleOutcome[randomNumber] | |
console.log('Son: The weather is ', result) | |
// Both rainy or sunny will be on resolve | |
if (result === 'Sunny' || result === 'Rainy') { | |
resolve(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sonChecksWeather = new Promise(function (resolve, reject) { | |
setTimeout(() => { | |
const possibleOutcome = ['Sunny', 'Rainy', 'Unexpected error'] | |
const randomNumber = Math.floor(Math.random() * 2) | |
const result = possibleOutcome[randomNumber] | |
console.log('Son: The weather is ', result) | |
// Both rainy or sunny will be on resolve | |
if (result === 'Sunny' || result === 'Rainy') { | |
resolve(result) |