0

I'm building an app to check the expiration dates of items. The functionality of the app works but I want to be able to check if a string includes a sub-string in order to run my function which is a countdown timer. I haven't included much of the code but it should be sufficient. Code is Bellow

var userInput = prompt("What item would you like to look up?");
  switch (userInput) {
    case userInput.includes("cous cous"):
//run a setInterval function
  • The the answers to the [linked question](https://stackoverflow.com/questions/17145723/how-can-i-use-ranges-in-a-switch-case-statement-using-javascript), including [mine](https://stackoverflow.com/questions/17145723/how-can-i-use-ranges-in-a-switch-case-statement-using-javascript/17145931#17145931). Yes you can. But you probably shouldn't. ;-) – T.J. Crowder Mar 17 '20 at 15:18

1 Answers1

1

case expression: resolves the expression and does an equality test of that value against the userInput.

Use an if() statement for this type of thing.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335