1

How can I repeat a letter or character for example "A" an X amount of times based on a string length number in Javascript? For example, user inputs the word "Outrageous" which has 10 letters and I want to output a * for each letter counted on from the input.

I tried this:

document.write("Your password " + str.replace(password.length),"*") + "has been accepted");

but it doesn't work

1 Answers1

0

Use String.repeat:

let password = "abcd";

let res = "x".repeat(password.length)

console.log(res)
Spectric
  • 30,714
  • 6
  • 20
  • 43