Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

need help on a nested Javascript table?

I've got a table for a nested function, the multiplication table. Before the nested function goes into a table it works fine... however,when it goes into the table, it comes out as table * n and not the values. Can any help on where the program is going wrong?

<html>

<head>

<title>Multiplication chart</title>

</head>

<body>

<h1> Multiplication Table </h1>

<script language="JavaScript">

<-

var n

var table

n=1

table=1

document.write('<table border="10" cellspacing="1" cellpadding="5">')

for (table=1; table<=6; table++)

{

document.write('<tr>')

for (n=1; n<=10; n++)

{

document.write('<td> (table * n) </td>')

}

document.write('</tr>')

}

document.write('</table>')

</script>

</body>

</html>

4 Answers

Relevance
  • Anonymous
    1 decade ago
    Favorite Answer

    I got it. Take out the <- you don't need that.

    And yes you can use document.write('<td>'+ table * n+' </td>') too.

    Good Luck!

    Source(s): JT Tech Support - http://support.jttechonline.com/
  • Relex
    Lv 4
    1 decade ago

    '<td> (table * n) </td>'

    Note how you set the quotes, this means that it's plain text / numbers. No action will be taken on this / code writting in here will be ignored.

    To fix it, you need to change it to this:

    '<td>' + table*n + '</td>'

    EDIT: JT whatever, is wrong. innerHTML is used to change content on the page, for a more dynamic effect.

    -What you want is for the JavaScript program to create the page for you automatically - you don't want to change the content from x to y. So just ignore that tip :3

    EDIT2: I forgot to tell you, in case you didn't know. In JavaScript, if you start an alert / .write or whatever, with a string, then the numbers will be converted from float to a string thus unabling direct math stuff in an alert. How to fix this:

    document.write('<td>' + eval(parseFloat(table) * parseFloat(n) + '</td>')

    I hope this helped!

    //Relex.

    Fixed & working. :3

  • 4 years ago

    for ( var rows = a million; rows <= n; rows++ ) { //initiate the table and the tr for ( var columns = a million; columns <= n; columns++ ) { //write the td } //end the tr and table } why yours does not artwork: a million. use are producing n*n tables, not n*n products/table cells 2. your columns additionally might desire to apply n

  • Anonymous
    6 years ago

    challenging problem. try searching onto yahoo or google. just that can help!

Still have questions? Get your answers by asking now.