Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
147
rated 0 times [  153] [ 6]  / answers: 1 / hits: 96847  / 10 Years ago, wed, february 26, 2014, 12:00:00

I am trying to create a simple times table in a html document using Javascript. This is my code so far:



<!DOCTYPE>
<html>
<head>
<title>Table</title>
</head>
<body>
<script language=javascript type=text/javascript>
for (var a=0; a < 10; a++) {
document.write(<tr>);
for(var b=0; b<10; b++) {
document.write(<td>a*b</td>);
}
document.write(</tr>);
}
</script>
</body>
</html>


I looked through the posted questions, but could not find an answer, possibly because I am a beginner programmer and did not understand most of it.


More From » for-loop

 Answers
94

Well, first of all you should insert the tr (rows) and td (cells) into a table element... Something like



document.write(<table>);
// your loop here
document.write(</table>);


There are better ways to do this, though!


[#72297] Tuesday, February 25, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
travion

Total Points: 137
Total Questions: 96
Total Answers: 103

Location: India
Member since Wed, Aug 4, 2021
3 Years ago
travion questions
Mon, Dec 16, 19, 00:00, 5 Years ago
Sat, Oct 19, 19, 00:00, 5 Years ago
Fri, Sep 20, 19, 00:00, 5 Years ago
Wed, Nov 14, 18, 00:00, 6 Years ago
Sun, Oct 28, 18, 00:00, 6 Years ago
;