samedi 31 juillet 2021

JS -- levels wont flow from one to the other in my work-tree of if this then return this message

I'm working on a tree/branch flow diagram where you input answers and it'll give you a reply working through the chart. However, I can't get my first level to connect with my second level. I can type in "name" and it will return correctly, but when I type in yes to answer then Do you like ice cream question. I get an undefined reply. Any help greatly appreciated.

let level = 0;
let path;

const getReply = (userInput) => {
if (level === 0) {
level = 1;
if (userInput === "name") {
  path = "name";
  return "Hello, name. Do you have like ice cream?";
}
}


if (level === 1) {
  level = 2;
  if (path === "yes") {
    if (userInput === "yes") {
      return "Great, what flavour do you like?";
  }
}

Aucun commentaire:

Enregistrer un commentaire