473,382 Members | 1,717 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Arrays

Below is a JavaScript program. How can I create an array and modify the code so that the table goes to 100 instead of 10?

I appreciate all your help

<?xml version = "1.0"?>
<!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><title>Table of Calculations</title>
<script type = "text/javascript">
<!--
document.write(
"<table width = '50%' border = '1'><tr> " +
"<th>number</th> <th>square</th> <th>cube</th>" );
document.write(
"<tr><th>" + 0 + "</th>" + "<th>" + 0 * 0 +
"</th>" + "<th>" + 0 * 0 * 0 + "</th></tr>" );
document.write(
"<tr><th>" + 1 + "</th>" + "<th>" + 1 * 1 +
"</th>" + "<th>" + 1 * 1 * 1 + "</th></tr>" );
document.write(
"<tr><th>" + 2 + "</th>" + "<th>" + 2 * 2 +
"</th>" + "<th>" + 2 * 2 * 2 + "</th></tr>" );
document.write(
"<tr><th>" + 3 + "</th>" + "<th>" + 3 * 3 +
"</th>" + "<th>" + 3 * 3 * 3 + "</th></tr>" );
document.write(
"<tr><th>" + 4 + "</th>" + "<th>" + 4 * 4 +
"</th>" + "<th>" + 4 * 4 * 4 + "</th></tr>" );
document.write(
"<tr><th>" + 5 + "</th>" + "<th>" + 5 * 5 +
"</th>" + "<th>" + 5 * 5 * 5 + "</th></tr>" );
document.write(
"<tr><th>" + 6 + "</th>" + "<th>" + 6 * 6 +
"</th>" + "<th>" + 6 * 6 * 6 + "</th></tr>" );
document.write( "<tr><th>" + 7 + "</th>" + "<th>" +
7 * 7 + "</th>" + "<th>" + 7 * 7 * 7 +
"</th></tr>" );
document.write(
"<tr><th>" + 8 + "</th>" + "<th>" + 8 * 8 +
"</th>" + "<th>" + 8 * 8 * 8 + "</th></tr>" );
document.write(
"<tr><th>" + 9 + "</th>" + "<th>" + 9 * 9 +
"</th>" + "<th>" + 9 * 9 * 9 + "</th></tr>" );
document.write( "<tr><th>" + 10 + "</th>" + "<th>" +
10 * 10 + "</th>" + "<th>" + 10 * 10 * 10 +
"</th></tr>" );
document.write( "</table>" );
// -->
</script></head><body></body></html>
Nov 26 '06 #1
3 944
AricC
1,892 Expert 1GB
There is a much prettier way to do this but you need to use a loop, Change index <= 100 to whatever number you want to see the square and cube of:

[html]<html>
<head><title>Table of Calculations</title>
<script type="text/javascript">
<!--
var index = 0;

document.write("<table width='50%' border='1'>");
document.write("<tr><td>Number</td><td>Square</td><td>Cube</td></tr>");

for( index=0;index <= 100; index += 1 )
{
document.write("<tr><td>" + index + "</td>" + "<td>" + index * index + "</td>" + "<td>" + index * index * index + "</td></tr>");
index += 1;
}

// -->
</script></head><body></body></html>[/html]
Nov 27 '06 #2
There is a much prettier way to do this but you need to use a loop, Change index <= 100 to whatever number you want to see the square and cube of:

[html]<html>
<head><title>Table of Calculations</title>
<script type="text/javascript">
<!--
var index = 0;

document.write("<table width='50%' border='1'>");
document.write("<tr><td>Number</td><td>Square</td><td>Cube</td></tr>");

for( index=0;index <= 100; index += 1 )
{
document.write("<tr><td>" + index + "</td>" + "<td>" + index * index + "</td>" + "<td>" + index * index * index + "</td></tr>");
index += 1;
}

// -->
</script></head><body></body></html>[/html]


Thank you so much for your help. I really appreciate it.
Nov 28 '06 #3
AricC
1,892 Expert 1GB
No problem kind of an interesting little script.
Nov 28 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

19
by: Canonical Latin | last post by:
"Leor Zolman" <leor@bdsoft.com> wrote > "Canonical Latin" <javaplus@hotmail.com> wrote: > > > ... > >But I'm still curious as to the rational of having type >...
21
by: Matteo Settenvini | last post by:
Ok, I'm quite a newbie, so this question may appear silly. I'm using g++ 3.3.x. I had been taught that an array isn't a lot different from a pointer (in fact you can use the pointer arithmetics to...
5
by: JezB | last post by:
What's the easiest way to concatenate arrays ? For example, I want a list of files that match one of 3 search patterns, so I need something like DirectoryInfo ld = new DirectoryInfo(searchDir);...
3
by: Michel Rouzic | last post by:
It's the first time I try using structs, and I'm getting confused with it and can't make it work properly I firstly define the structure by this : typedef struct { char *l1; int *l2; int Nval; }...
1
by: Rob Griffiths | last post by:
Can anyone explain to me the difference between an element type and a component type? In the java literature, arrays are said to have component types, whereas collections from the Collections...
41
by: Rene Nyffenegger | last post by:
Hello everyone. I am not fluent in JavaScript, so I might overlook the obvious. But in all other programming languages that I know and that have associative arrays, or hashes, the elements in...
6
by: Robert Bravery | last post by:
Hi all, Can some one show me how to achieve a cross product of arrays. So that if I had two arrays (could be any number) with three elements in each (once again could be any number) I would get:...
1
by: Doug_J_W | last post by:
I have a Visual Basic (2005) project that contains around twenty embedded text files as resources. The text files contain two columns of real numbers that are separated by tab deliminator, and are...
16
by: mike3 | last post by:
(I'm xposting this to both comp.lang.c++ and comp.os.ms- windows.programmer.win32 since there's Windows material in here as well as questions related to standard C++. Not sure how that'd go over...
29
weaknessforcats
by: weaknessforcats | last post by:
Arrays Revealed Introduction Arrays are the built-in containers of C and C++. This article assumes the reader has some experiece with arrays and array syntax but is not clear on a )exactly how...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.