Check my code

S

shannon

Hi
Can anyone tell me what i'm doing wrong.I'm asking the user to enter
their name and seat class either economy or first class. I want to
store than information in an array and print the passenger information
on the screen.

<html>
<head>
<title>Airline Booking</title>

<script type="text/javascript">

var myairline = new Array(10);
var first = 0;
var economy = 5;
var name;
var class;
<!-- Hide JavaScript from older browsers

//enter details
name=window.prompt("Please Enter your name");
class=window.prompt("Please Enter flight class. Enter 1 for first
class, 2 for second class");

//the following two if statements were put in instead of using a
function


if ( first == 4 && class == 1 ){
window.alert( "Do you want second class?" );
if (class == 2){
class=2;
}
}

if (economy == 9 && class == 2){
window.alert( "Do you want first class?" );
if (class == 1){
class=1;
}
}

//if the flight class is first class
if ( class = 1 ){

//this statement checks if the array is full (might need break
statement)
if (first == 4){
window.alert( "Next Plane leaves in 3 hours" );
}
//puts name into first class seat of array
array[first]=name;

//increments the index(also seat number) of the array and
prints out this new seatnumber, class and passenger name
first++;
document.write("Class: First Class, Passenger:+array[first]+<br
/>");
}

//if the flight class is economy class
if ( class = 2 ){

//this statement checks if the array is full (might need a
break statement to get out)
if (economy == 9){
window.alert( "Next Plane leaves in 3 hours" );
}
//puts name into economy seat of array
array[economy]=name;

//increments the index(also seat number) of the array and
prints out this new seat class and passenger name
first++;
document.write("Class: Economy Class,
Passenger:+array[first]+");
}

//print details
for (i=0;i<myairline.length;i++){

//flight details are output to the screen
document.write(myairline ++ "<br />")
}

// End hiding JavaScript from older browsers -->
</script>
</head>
</html>
 
V

VK

To shannon:
"class" is a reserved word in JavaScript, you cannot use it a a
variable name.

To any school informatics teachers who may occur around:

JavaScript is "in-browser" language, it doesn't have C-like console in
/ out.

document.write() is not a replacement as it clears the page if called
after the page is loaded.

So if you're giving an assignment to your class which cannot be done in
a single pass algorithm, please explain to your class why
document.write() cannot be used *and* provide some simple HTML
interface for the assignment. The simpliest one would be a form with
textarea in it.
 
T

Thomas 'PointedEars' Lahn

VK said:
To any school informatics teachers who may occur around:

JavaScript is "in-browser" language, it doesn't have C-like console in
/ out.

Wrong. JavaScript is a programming language running in a host environment.
Its capabilities regarding input/output device depend on interfaces of the
host environment.

That goes for JScript and other ECMAScript implementations as well.
document.write() is not a replacement as it clears the page if called
after the page is loaded.

However, there are both standardized (W3C DOM) and proprietary (IE DOM)
methods available to work around that.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top