'Javascript If Else Conditional Statement

If the user tries to get a beverage without placing their cup on the tray, display “Please place your cup on the tray.” If it is the custom refillable cup, display “Custom Refillable cup: Please make your selection.” If it is the custom non-refillable cup AND it is the first time using it, display “Custom Non-Refillable cup: You have one fill remaining; Please make your selection.” If it is the custom non-refillable cup AND it is NOT the first time using it, display “Custom Non-Refillable cup: You have zero fills remaining; Please leave.” If it is not either of the custom cups, display “This is an invalid cup; Please leave."

the problem i'm having is after it asks you if you have the refill cup and you say no it says is it first time use. its suppose to be after you say no if you have a refill cup then it asks you if you have the nonrefill cup and then it asks if its your first time using cup im missing the "do you have non refillable cup" prompt every time i try a way to add it in it never works right

My code so far :

alert("Please put cup on the tray.")

let theCup = window.prompt("Did you place the cup on the tray? (type yes or no.)");
if (theCup === 'yes') {
    alert("Please choose your cup.")
}

let yourCup = window.prompt("Do you have a Refill cup or a NonRefill cup?");
if (yourCup === 'yes') {
    alert("Please choose your cup");

  let refillCup = window.prompt("Do you have a refill cup?");
  if (refillCup === 'yes') {
    alert("Custom Refillable cup:Please make your selection");
  } else {
    let firstUse = window.prompt("Is it the first time use? (Answer must be yes or no.)");
    if (firstUse === 'yes') {
      alert("Custom Non-Refillable cup: You have one fill remaining; Please make your selection.");
    } else {
      alert("Custom Non-Refillable cup: You have zero fills remaining; Please leave.")
    }
  }
} else {
    alert("This is an invalid cup; Please Leave.")
}


Solution 1:[1]

In your current code, you are stating that if the refillCup is not equal to yes, then it should ask whether it is the first time.

  let refillCup = window.prompt("Do you have a refill cup?");
  if (refillCup === 'yes') {
    alert("Custom Refillable cup:Please make your selection");
  } else {
    let firstUse = window.prompt("Is it the first time use? (Answer must be yes or no.)");

It is somewhat hard to read what you wrote, but just replace the last line of this piece of code with whatever function you want it to perform. Your question is not grammatically accurate.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Aykhan