My code is setup to check for special characters inside of a given password. The program is suppose to store true to a variable if a special character was found, and false if one was not found; Afterwards, it will print the result of the variable. The problem is the program keeps printing out false even when there’s a special character inside of the password. I don’t know what’s wrong
const arrayOfSp = ["!", "@", "#", "$", "%", "&", "*", "_", "-", "?"];
const password = "Patrick_";
let specialCharacterCheck = false;
const special = (c) => {
for (i = 0; i < arrayOfSp.length; i++)
{
if (c === arrayOfSp[i])
{
return true;
}
}
return false;
}
for (i = 0; i < password.length; i++)
{
if (special(password[i]))
{
specialCharacterCheck = true;
}
}
console.log(specialCharacterCheck);