-1

Trying to run a if statement based off a user input, would this be the correct way? So if the user is on a subscription then isSubscription is true.

var subscription = window.alert("Is this a subscription? (Y/N)"); 
    if (subscription == "Y") {
        isSubscription = true;
      } else {
        isSubscription = false;
        window.alert("No activation key");
      }
CC41325
  • 53
  • 1
  • 2
  • 8
  • https://stackoverflow.com/questions/9334636/how-to-create-a-dialog-with-yes-and-no-options – mbozwood Nov 15 '17 at 16:18
  • Possible duplicate of [How to create a dialog with “yes” and “no” options?](https://stackoverflow.com/questions/9334636/how-to-create-a-dialog-with-yes-and-no-options) – Federico klez Culloca Nov 15 '17 at 16:19

2 Answers2

2

Try to use window.confirm. It has built in yes/no feature, where value returned are true for yes/ok and false for no/cancel.

So your code would look like

isSubscription = window.confirm("Is this a subscription?")

Read more at:

https://developer.mozilla.org/en-US/docs/Web/API/Window/confirm

Mario Nikolaus
  • 2,346
  • 1
  • 21
  • 28
1

Try like this way,

var subscription = window.confirm("Is this a subscription? (Y/N)"); 

    if (subscription == true) {
        window.alert("activation key available");
        isSubscription = true;
      } else {
        isSubscription = false;
        window.alert("No activation key");
      }
A l w a y s S u n n y
  • 36,497
  • 8
  • 60
  • 103