Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can you assign mutiple values to this? and if so, how?

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!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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/";
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading