I have javascript code which is a variable called "x" which value is "Hello World". And also there are two other variables named "old" and "new". All I want is to when I give a random value to variable "Old" and new value to variable "new". Then I need the program to find and replace the similar character in the sentence with the new value.
Ex : old = "l" , new = "y", new sentence would need to become "Heyyo World" which replace the 'l' letter with 'y'.
Below is my sample code.
<script type="text/javascript">
function fndReplace()
{
var x = "Hello world";
var old = "l";
var neww = "y";
var i;
var length = x.length;
for(i=0;i<length-1;i++)
{
if(old[i] == neww)
{
old = old[i] + neww
}
}
document.write(old);
}
fndReplace();
</javascript>