Pages

Sunday, November 10, 2013

Program 1 (b)

1 b)

Develop and demonstrate a XHTML file that includes Javascript script
for the following problems:
Input:     A number n obtained using prompt
Output:  A table of numbers from 1 to n and their squares using alert


<html>
<body>
<center>
<script>
function square()
{
var n=prompt("Enter the Number"," ");
str1="No--------------------Square\n";
n=parseInt(n);
if(n>0)
{
for(i=0;i<n+1;i++)
{
temp=i*i;
str1=str1+i+"----------------------"+temp+"\n";
}
alert(str1);
}
else alert("Enter a number greater than 1.")
}
</script>
<body>
<form>
<br><br><br>
<input type="button" value="Enter Number" onclick="square()";>
</form>
</center>
</body>
</html>


 

No comments:

Post a Comment