Home > Back-end >  Can you assign mutiple values to this? and if so, how?
Can you assign mutiple values to this? and if so, how?

Time:03-10

I'm trying to code a password variable that can hold multiple values so any of the following passwords can work and give access to the site.

var pass1="testpass1", "testpass2";

password=prompt('Whats the pass?',' ');

if (password==pass1)
  alert('ja');
else
   {
    alert('nein')
    window.location="https://google.com/";
}

I really need to figure this out.

Thank you!

CodePudding user response:

You could make pass1 an array and then use the .includes method like so:

let pass1=["testpass1", "testpass2"];

password=prompt('Whats the pass?');

if (pass1.includes(password)){
  alert('ja');
}
else{
    alert('nein')
    window.location="https://google.com/";
}
  • Related