SitePoint Sponsor |
|
User Tag List
Results 1 to 2 of 2
Thread: Please can someone help!!!
-
Dec 1, 2002, 15:16 #1
- Join Date
- Dec 2002
- Posts
- 7
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Please can someone help!!!
The following script fragment will produce the seven times table, as shown.
<SCRIPT LANGUAGE="JavaScript">
var tableNumber = 7
var thisResult = 0
for ( var tableIndex = 1;
tableIndex <= 12;
tableIndex++) {
thisResult = tableIndex * tableNumber
document.write( tableIndex + " times " +
tableNumber + " is " +
thisResult + "<BR>")
} <!-- End for -->
</SCRIPT>
How do I adapt the script so that it names the numbers, for example the last line of the table should be.
twelve times seven is eighty four
not
12 times 7 is 84
Thanx for anyone that can help me
-
Dec 1, 2002, 17:41 #2
- Join Date
- Dec 2002
- Posts
- 8
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Maybe you can try this
Hi. I don't code javascript, but maybe you can use an array to store the strings representing the numbers. After that you can index that array using your tableNumber and tableIndex. For example:
// Put all of the strings in an aray
var numbers = new Array("zero","one", "two", "three", ...);
After that, you can do this:
document.write( numbers[tableIndex] + " times " +
numbers[tableNumber] + " is " +
numbers[thisResult] + "<BR>")
This is just a suggestion. It may be inefficient for what you are doing, but it should work. (Sorry if the syntax for the script is incorrect)
Bookmarks