Slip 16 - A) Write a java script code to accept a sentence from the user and alters it as follows: Every space is replaced by * and digits are replaced by ?

Solution:


<HTML>
<script>
function find()
{
var str=frm.txt1.value;
var n = str.length;
var i,ch,j;
for(i=0;i<n;i++)
{
str = str.replace(" ", "*");
str = str.replace(/[0-9]/g, "?")
}
alert(str);
}
</script>
<form name="frm">
Enter a String:<input name="txt1" type="text" />
<input name="b1" onclick="find();" type="button" value="display" /></form>
</BODY>
</HTML>

Post a Comment

0 Comments