SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Dec 2002
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question 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

  2. #2
    SitePoint Member
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •