Question for a Book (Inernet & WWW How to program)

Write a JavaScript program that uses Looping to print the following table of valuses. Qutput the results in an XHTML table.

N 10* 100* 1000*
1 10 100 1000
2 20 200 2000
3 30 300 3000
4 40 400 4000
5 50 500 5000

Recommended Answers

All 7 Replies

Member Avatar for GreenDay2001

i didnt understand whats

N 10* 100* 1000*

Member Avatar for GreenDay2001

wait:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
  <title></title>
  <script language="JavaScript" type="text/javascript">
  /*<![CDATA[*/
  var a=10;
  document.write("<table border='1'>")
  document.write("<tr><td>N</td><td>10*</td><td>100*</td><td>1000*</td></tr>")
  for(i=1;i<=5;i++)
  {
    document.write("<tr><td>"+i+"</td><td>"+i*a+"</td><td>"+i*a*a+"</td><td>"+i*a*a*a+"</td></tr>");
  }
  document.write("</table>");
  /*]]>*/
  </script>
</head>

<body>

</body>

</html>

OMG! thank your very much. Just one question how did you use looping. I mean in which lines? thx again :)

Hi There,

Well code that wrote by vishesh doing the same thing that you want :)
Just he miss ";" two place, just add and code will run

And you can use the this code as well

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script language="JavaScript" type="text/javascript">
//<![CDATA[

		document.write("<table width='600' border='1' cellspacing='3' cellpadding='3'>");
		document.write("<tr>");
		document.write("<th>N</th>");
		document.write("<th>10*</th>");
		document.write("<th>100*</th>");
		document.write("<th>1000*</th>");
		document.write("</tr>");
		        
                        //This is Looping 
                        var num = 1;
                     
			for (var x=1; x <= 5; x++)
			{
				document.write("<tr><td>" + num*1 + "</td><td>" + num*10 + "</td><td>" + num*100 + "</td><td>" + num * 1000  + "</td></tr>");
				num = num + 1;
			}
		document.write("</table>");
//]]>
</script>
</head>
<body>
</body>
</html>

sorry for editing this post again:

here the validation result

http://validator.w3.org/check?uri=http%3A%2F%2Fwww.katarey.com%2Fdownloads%2FrandomCss%2F1.html&charset=%28detect+automatically%29&doctype=Inline


Best regards,
Rahul Dev

ohh!! thx man ... :) :)

Member Avatar for GreenDay2001

OMG! thank your very much. Just one question how did you use looping. I mean in which lines? thx again :)

for(i=1;i<=5;i++)
  {
    document.write("<tr><td>"+i+"</td><td>"+i*a+"</td><td>"+i*a*a+"</td><td>"+i*a*a*a+"</td></tr>");
}

this is for loop. the for loop first initialises variable i to 1 i=1 and everytime increments it by 1 i++ until i becomes greater than or equal to 5. And every time i increments it executes

document.write("<tr><td>"+i+"</td><td>"+i*a+"</td><td>"+i*a*a+"</td><td>"+i*a*a*a+"</td></tr>");

this line just write the table row and cells.

oh! ok thx a lot again man :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.