How do I insert a hyphen after every 3
characters in a string? Here's what I've tried:
var str = prompt().split("").join(""); // i used split() to convert string to array and join() to remove (,)
var i = 0;
var l = 2;
while (i < str.length) {
str[l] = "-"; // i think it should puts - every three character but it doesn't
l += 3;// i think it should puts - every three character but it doesn't
i += 1;
};
alert(str);