hi, i’m wondering why this doesn’t work and how can i fix it? I already know one method with the split and then join. However, the below example seems to result in buggy situations where sometimes it works and sometimes it doesn’t. Could someone explain the logic please and how to fix it?
Thanks
function correct(string)
{
var newword = ""
for (var i=0; i < string.length; i++) {
if (string.charAt(i) == "5") {
var result = string.replace(/5/g,'S');
}
if (string.charAt(i) == "0") {
result = string.replace(/0/g,'O');
}
if (string.charAt(i) == "1") {
result = string.replace(/1/g,'I');
} console.log(result)
}
}