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
  • 17,134
  • 11
  • 53
  • 79

2 Answers2

3

You can use indexOf, for example:

if (manager.indexOf(position) !== -1) {
    alert("manager");
}
James M
  • 18,506
  • 3
  • 48
  • 56
0

Use .indexOf()

if (manager.indexOf(position) != -1) {
   alert("manager")
}
Amit Joki
  • 58,320
  • 7
  • 77
  • 95