Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Apr 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    booking system with JS

    Hi there,
    i got this code with me, but i couldnt find uot why it could not run.
    I run this code in frontpage, and it says it has variable undefined on line 18.
    please help
    tha


    <?xml version = "1.0"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

    <!-- Fig. 7.2: welcome2.html -->
    <!-- Printing a Line with Multiple Statements -->

    <html xmlns = "http://www.w3.org/1999/xhtml">
    <head>
    <title>Airline Reservation System</title>

    <script type = "text/javascript">
    <!--
    //initializing variables in declaration
    var passenger = 1,
    var firstclass = 0,
    var economy = 0,
    var type;

    function initializeArrays()
    {
    var firstclass = new Array( 5 ); //allocate 5-element array
    var economy = new Array(); // allocate empty array

    //assign values to each element of array firstclass
    for ( var i = 0; i < n1.length; ++i )
    n1[ i ] = i;

    //create and initialize five elements in Array economy
    for ( i = 0; i < 5; ++i )
    n2[ i ] = i;


    //process 10 passengers
    while ( passenger <= 10 ) {
    result = window.prompt(
    "Enter type (1=Firstclass,2=Economy)", "0" );

    if ( type == "1" )
    firstclass = firstclass + 1;
    else
    economy = economy + 1;
    }

    // termination phase
    document.writeln( "(h1)Your ticket number: " + var firstclass ;










    // -->
    </script>

    </head><body></body>
    </html>


    <!--

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,922
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    The arrays n1 and n2 are not defined.

    Try changing

    var firstclass = new Array( 5 ); //allocate 5-element array
    var economy = new Array(); // allocate empty array

    to

    var n1 = new Array( 5 ); //allocate 5-element array
    var n2 = new Array(); // allocate empty array


  •  

    Posting Permissions

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