-1

I need to have a window prompt the user if they want to use alphabetic characters when generating a suggested password, when I insert the following code into my javascript below, it executes the prompt, but doesnt maintain the while loop or execute the conditional statements, can anyone help?

while (vallidated === false) {
  var usingChars = prompt("Hello! Would you like to use letters in your password? Y / N ")
  if (useChars === 'y' || 'Y') {
    usechars = true;
    vallidated = true;
  }
  else if (usingChars === 'n' || 'N') {
    useChars = false;
    vallidated = true;

  }
  else {
    prompt("Invalid input! Please enter the letter Y or N.")
  }
}
Codebling
  • 10,764
  • 2
  • 38
  • 66
  • 5
    `useChars==='y' || 'Y'` is not the correct way to check for `y` or `Y`. The correct code is `useChars==='y' || useChars=== 'Y'` – VLAZ May 13 '21 at 20:54
  • Does this answer your question? [Javascript: The prettiest way to compare one value against multiple values](https://stackoverflow.com/questions/9121395/javascript-the-prettiest-way-to-compare-one-value-against-multiple-values) – Wyck May 13 '21 at 21:00

1 Answers1

1

Your problem is that you are using an undefined variable when checking the input.

You set usingChars to the prompt, but then check the value of useChars instead of usingChars.

Dan Mullin
  • 4,285
  • 2
  • 18
  • 34