473,659 Members | 2,656 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>Airlin e 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.pro mpt("Please Enter your name");
class=window.pr ompt("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:+arra y[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:+arra y[first]+");
}

//print details
for (i=0;i<myairlin e.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 1715
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
29893
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 *** Don't just participate in USENET...get rewarded for it!
7
2449
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. Only problem is: when the user clicks on it, there's a beep, and then they get a status bar message: "Control can't be edited; it's bound to the expression...." That's very annoying and disconcerting. Is there a way to trap the click and...
3
32335
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
4258
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 require checking a check box to tell which category something will pertain to. Well after each record is entered i want the check to remain with that record and auto clear when going to the next record so i can input something else if i have a...
14
2341
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 we have some way to contact the customer. Today I check for the existence of an email-address, and a validation code - what I need is a way to check, eg. whether email _or_ phone is entered, and if none is entered, display an errorpage.
2
3587
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 check/uncheck it. Also, what event do I use to check it for a value? Any articles out there? -- Chris Davoli
19
107940
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 sure that the user only submits a number to your .NET web application and also demonstrate how to add JavaScript to your ASPX pages. Upon popular demand, I have added a section that also covers how to use a validator control to check if a text box...
5
6732
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 (SQL -Change Card List). What I want to do is have the form open the report where a filter is set to use the values from the check box AND the value selected from the list box to generate the report. What I can't figure out is how to use the...
55
3296
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 non business logic related code block)? The following code from net-snmp library calls atoi five times but checks none. Do we code a wrapper my_atoi_with_error_check() around atoi and call this new one everywhere else? Is it a good practice...
1
2405
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. I want to display these results in check boxes. This is my code. But it doesn't work <tr><td><input value="1" type="checkbox" id="1" name="check" <?php if ($array==1) echo "value=checked";?>/>Fasting 6 hours</td> <td><input value="2"...
0
8427
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8332
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8627
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2750
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 we have to send another system
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.