0
var position = prompt("position:");
var manager = ["John", "Alex", "Joe"];
var admin = ["Texas", "Jesus", "Rick"];
var tech = ["Nexus", "Thomas", "Fred"]
if (position == manager) {
alert("manager")}

if (position == admin) {
  alert("admin")}

if (position == tech) {
  alert("tech")
}

else {
  alert("Incorrect position")

}

I would like to ask how it is possible to this program work. When I will enter in prompt John I would like to get alert manager when I will enter in prompt Rick I would like to have alert tech etc...

And also if I will enter something what is unknown random value it will get me Incorrect position.

Also I would like to ask if there is way when I will enter in prompt for example jOHN or john it will work. I am total beginner in JS and coding.

andand
  • 16,364
  • 9
  • 51
  • 77

2 Answers2

3

You can use indexOf, for example:

if (manager.indexOf(position) !== -1) {
    alert("manager");
}
James McLaughlin
  • 18,774
  • 3
  • 47
  • 56
0

Use .indexOf()

if (manager.indexOf(position) != -1) {
   alert("manager")
}
Amit Joki
  • 56,285
  • 7
  • 72
  • 91