Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q1462 How do I build a 10 times table in JavaScript where the numbers divisible by X are highlighted?

You are here: irt.org | FAQ | JavaScript | Table | Q1462 [ previous next ]

Try:

<script language="JavaScript"><!--
var X = 7;
var Text = '<table><tr>';
var Cells = 100;

for (i=1;i<=Cells;i++) {
  if (i%X==0) Text += '<td><font color="red">' + i + '</font></td>';
  else Text += '<td>' + i + '</td>';
  if (i%10 == 0 && i<Cells) Text += '</tr>\n<tr>';

}
Text += '</tr></table>'
document.write(Text);
//--></script>

©2018 Martin Webb