I want to replace any 3 random letters from the string with random letters from my letters
variable
var str = "HELLO";
var letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var arr = str.split('');
for (var i = 0; i < 3; i++) {
var pos = Math.round(Math.random() * arr.length - 1);
arr.splice(Math.floor(Math.random() * arr.length), 1);
str = arr.join('');
}
alert(str);
I am able to take 3 random letters out right now but can't figure out how to get 3 random letters from letters
and put them in a random position.
Here is the demo of what I have right now.
Any help would be appreciated!
Aucun commentaire:
Enregistrer un commentaire