Question: In Javascript, how do you check if the user's input is one of the elements in an array? I want to print an error message

In Javascript, how do you check if the user's input is one of the elements in an array? I want to print an error message if it is not.

e.g.

var numbers = [1, 2, 3, 4]

var choice = parseint(prompt("Enter a number between 1-4")

// if the choice is not in numbers, I want to print an error message

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!