Slip 2 - A) Write a java script program to accept a number form user and display its multiplication table

Solution:

<html>

<body>

<script type='text/javascript'>

var num = prompt("Enter Number", "0") //prompt user to enter the number

var num = parseInt(num); //parse the num to number

var i = 0;

document.write('<table border="1" cellspacing="0">');

for(i=1;i<10;i++) {

document.write("<tr><td>" + num + " x " + i + " = " + num*i + "</td></tr>");

}

document.write("</table>");

</script>

</body>

</html>

Post a Comment

0 Comments