473,503 Members | 1,725 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Check my code

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[i] ++ "<br />")
}

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

Nov 23 '05 #1
2 1705
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.

Nov 23 '05 #2
VK wrote:
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
Nov 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
29845
by: Tony Johnson | last post by:
Can you make a check box very big? It seems like when you drag it bigger the little check is still the same size. Thank you, *** Sent via Developersdex http://www.developersdex.com ***...
7
2436
by: Neil | last post by:
I have a check box on a form that's bound to a function that returns a True/False value. When the user clicks on the check box, I run some code through the MouseDown event. Everything works fine. ...
3
32290
by: Al | last post by:
Hello, Sorry for the silly question: How do I insert Check Mark into RichTextBox? I can’t find the ascii code for it. Thanks Alex
1
4244
by: scprosportsman | last post by:
Please help guys, i am trying to set up a database here at work and im fairly new to access in terms of writing functions and queries and stuff. I have 2 different places on my design that will...
14
2331
by: Ørjan Langbakk | last post by:
I have a form where the user has the possibility to enclose his name. email, address and phonenumber. I want to be able to check if some of the fields are filled - at least one. This is so that...
2
3579
by: Chris Davoli | last post by:
How do you enable a check box in the GridView. I selected Checkbox Field in the Columns of the GridView, and the check box shows up in the Grid view, but it is disabled. How do I enable it so I can...
19
107856
Frinavale
by: Frinavale | last post by:
Filtering user input is extremely important for web programming. If input is left unfiltered users can input malicious code that can cripple your website. This article will explain how to make...
5
6705
by: Andrew Meador | last post by:
I have a form (Change Card List by Status) with a check box (cboNOT) and a list box (lstStatus). There is an Open Report button that opens a report (Report - Change Card List) which uses a query...
55
3249
by: lovecreatesbea... | last post by:
Do you check all error conditions for all library calls in you code? Is it necessary to check all errors? Is it convenient to check all errors (or how to make code clean and readable with mass of...
1
2398
by: ghjk | last post by:
my php page has 7 check boxes. I stored checked values to database and retrive as binary values. This is the result array Array ( => 0 => 1 => 0 => 1 => 0 => 0 => 1 ) 1 means checked....
0
7202
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7086
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7280
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7332
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7462
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
382
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.