Slip 11 - A) Write a JavaScript program to accept a string and a position (number) from user and display the character at specified position.

Solution:

<html>

<body> 

<script type = "text/javascript">

var str=new String(prompt("Enter a string"));

for(i=0;i<str.length;i++)

{

document.writeln("<br />str.charAt("+i+") is:" + str.charAt(i));

}

</script>     

</body>

</html>

Post a Comment

0 Comments