...

View Full Version : booking system with JS



fvnnmike
04-13-2005, 04:08 AM
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>


<!--

Philip M
04-13-2005, 07:26 AM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum