Skip to content
Advertisement

How do I restrict the user input to particular strings, which are already stored as a variable(s)?

I am creating a web-scraping tool for some gift cards, and I have stored the name of each gift card (which is a string, i.e “PSN”) as a variable. So for example, P = “PSN”

I have a user input asking them to put in the name of the card they’re after, but I want it to be restricted to the variables I have already defined, so that if they type a name other than the cards I have already allowed for, it will return an error and ask them to type the name again.

How can I go about this?

Here is the code I’ve written so far:

JavaScript

Advertisement

Answer

Like this:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement