JSFiddle - React, Tailwind, and code Playground

HTML

<script>
function locate() {
	//const msg = "in the office"; // choose either one to return, can comment the other out.
  const msg = "in the kitchen";
  var obj = {body: msg};
  return Promise.resolve(obj);
}

function addSalt(salt) {
    console.log("addSalt");
    return Promise.resolve("We added salt");
}

function run() {
    console.log("We are running");
    return Promise.resolve("Running");
}

function conditionalChaining(value) {
    if (value.body === 'in the kitchen') {
        //do addSalt then run
        return addSalt("some salt value since its undefined by u").then(run);
    } else if ( value.body === 'in the office' ) {
      console.log("hey you are in the office");
    } else {
        //run
        return run();
    }
}

// in this function, you are suppose to resolve the string "in the kitchen" or "in the office"
// this is so that the conditionalChaining function takes in either of the string and process the next action.
function myPromiseFunction() {
    return Promise.resolve(locate());
}

myPromiseFunction().then(conditionalChaining).then(function () {
    console.log("All done!");
});
</script>