const input = document.createElement("input");
input.type = "password";
input.placeholder = "Enter password";
document.body.appendChild(input);

const meter = document.createElement("p");
meter.textContent = "Strength: -";
document.body.appendChild(meter);

function scorePassword(pw) {
  let score = 0;
  if (pw.length >= 8) score++;
  if (/[A-Z]/.test(pw)) score++;
  if (/[a-z]/.test(pw)) score++;
  if (/[0-9]/.test(pw)) score++;
  if (/[^A-Za-z0-9]/.test(pw)) score++;
  return score;
}

const labels = ["Very weak", "Weak", "Fair", "Good", "Strong", "Excellent"];
const colors = ["#c00", "#e60", "#e90", "#9a0", "#3a0", "#080"];

input.addEventListener("input", () => {
  const score = scorePassword(input.value);
  meter.textContent = "Strength: " + labels[score];
  meter.style.color = colors[score];
});