/    Sign up×
Community /Pin to ProfileBookmark

Simple table of numbers

I want to use document.write to make a html-table that multiplies numbers, like this:

number number*number number*number*number

I want to be able to define for how long this loop shall continue, preferrably by typing in the highest value of “number” into a prompt.
So if I define it as three the table should look like this:

1 1 1
2 4 8
3 9 27

Please help ?

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@PittimannMar 15.2004 — Hi!

Hope, you know, what you are doing :p! Here's some code:
[code=php]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script language="JavaScript" type="text/javascript">
<!--
function makeTable(){
var count=1
var insert='<table>';
for (var i = 1;i<=Number(document.forms[0].myNumber.value);i++){
insert +='<tr>';
for (var k = 1;k<=Number(document.forms[0].myNumber.value);k++){
insert +='<td>'+(Math.pow(i,k))+'</td>';
}
insert +='</tr>';
}
insert +='</table>';
document.write(insert);
}
//-->
</script>
</head>
<body>
<form>
<input name="myNumber">
<input type="button" value="make table" onClick="makeTable()">
<form>
</body>
</html>
[/code]

Cheers - Pit

P.S.: I hope, your machine doesn't explode, if the number you enter is too high ?
×

Success!

Help @ana66 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...