booking system

S

shannon

Hi all,

i am new to javascript and was wondering if anyone can help with this
assignment?

Any help will be great.

Shannon

A small airline has just purchased a computer for its new automated
reservation system. You have been asked to program the new system. You
are to write a JavaScript program to assign seats on the next flight of
the airline's only plane (capacity 10 seats). Your program should
display a web page that asks for the passenger name and provides the
following alternatives: Please type 1 for "First Class" and Please
type 2 for "Economy". If the person types 1, your program should
assign a seat in the first class section (seats 1-5). If the person
types 2, your program should assign a seat in economy section (seats
6-10). Your program should output boarding pass information indicating
the passenger name, seat number, and whether it is in the first class
or economy section of the plane.
Your program should, of course, never assign a seat that has already
been assigned. When the first class section is full, your program
should ask the person if it is acceptable to be placed in the economy
section (and vice versa). If yes, then make the appropriate seat
assignment. If no, then output the message: " Next flight leaves in 3
hours."
Your program should be able to output a list of passengers who have
reservations.
Hint: Use an array to represent the seating chart of the plane. As each
seat is assigned, store the passenger name in the corresponding array
element to indicate that the seat is no longer available.
 
H

Hywel Jenkins

Hi all,

i am new to javascript and was wondering if anyone can help with this
assignment?

Any help will be great.

What has your tutor said? As this requires more than basic JS
knowledge, I suspect you've missed something at school.
 
T

Thomas 'PointedEars' Lahn

shannon said:
i am new to javascript and was wondering if anyone can help with this
assignment?
[...]
[homework]

Sorry, the whole idea of homework is that _you_ do it to teach yourself
(work at home), not be teached by others. I think if you posted code
snippets of your non-working approach to solve the problem, all here will
gladly clarify any misconceptions that caused it. But first it is up to
_you_ to develop that approach in order to show that you have understood
the basics you should have learned in class. Think about it: Would you
like to work with people who do not know what they do? Would you employ
such a person?

<http://jibbering.com/faq/>


PointedEars
 
S

shannon

I have been attending classes and trying to figure this out. Can you
help me with this piece, i think the if statement is not executing
properly.

<html>
<HEAD>
<TITLE>Performing Comparisons</TITLE>

<SCRIPT LANGUAGE = "JavaScript">

var passengerName; // first string entered by user
var seatType; // second string entered by user
var classType;


// read first number from user as a string and assigns to var first
passengerName = window.prompt( "Enter your name:", "0" );

// read second number from user as a string and assigns to var
second
seatType = window.prompt( "For First Class type 1 or 2 for
Economy:", "0" );

if (seatType ==1){
classType = ("First Class");
Else
classType=("Economy")};

document.writeln( "<H1>Boarding Pass Information</H1>" );
document.writeln( "<TABLE BORDER = \"1\"" + "WIDTH = \"40%\">");


document.writeln( "<TR><TD>" + "<b>" +"NAME:" + "</b>" +
"</TD></TR>" );


document.writeln( "<TR><TD>" + passengerName +
"</TD></TR>" );


document.writeln( "<TR><TD>" + "<b>" + "SEAT TYPE"+ "</b>" +
"</TD></TR>" );


document.writeln( "<TR><TD>" + seatType+
"</TD></TR>" );


document.writeln( "<TR><TD>" + "<b>" + "CLASS TYPE"+ "</b>" +
"</TD></TR>" );


document.writeln( "<TR><TD>" + classType +
"</TD></TR>" );


document.writeln( "</TABLE>" );
</SCRIPT>

</HEAD>
<BODY>
<P>Click Refresh (or Reload) to run the script again</P>
</BODY>
</HTML>
 
R

Randy Webb

shannon said the following on 11/18/2005 4:52 PM:
I have been attending classes and trying to figure this out. Can you
help me with this piece, i think the if statement is not executing
properly.

if (seatType ==1){
classType = ("First Class");
Else

else != Else

You should get a syntax error on the above line.

You also have bracket mismatch.

if (condition){
//true branch
}
else{
//false branch
}
 
T

Thomas 'PointedEars' Lahn

shannon said:
<SCRIPT LANGUAGE = "JavaScript">

If you have learned that in class, it is wrong. The `language' attribute is
deprecated, the `type' attribute is required for HTML4's `script' element.
Use

<script type="text/javascript">

Use <URL:http://validator.w3.org/> to identify other invalid markup
which could (and will) affect the proper execution of your script code
that is operating on it.
var passengerName; // first string entered by user
var seatType; // second string entered by user
var classType;


// read first number from user as a string and assigns to var first
passengerName = window.prompt( "Enter your name:", "0" );

// read second number from user as a string and assigns to var
second
seatType = window.prompt( "For First Class type 1 or 2 for
Economy:", "0" );

if (seatType ==1){
^
window.prompt() returns either a string or `null'. You are relying
on automatic type conversion of the number 1 to string due to its
comparison with a string. Not a Bad Thing, but something to watch for.
classType = ("First Class");

So you open the block above with `{' but do not close it with `}'.
v
^^^^
As JS/ECMAScript is case-sensitive, there is no `Else' statement
but an `else' statement. Probably but a typo you overlooked :)
classType=("Economy")};
^
There. You are closing the block too late. It should be

if (...)
{
// ...
}
else
{
// ...
}

Consequent proper indentation helps :)
document.writeln( "<H1>Boarding Pass Information</H1>" );
document.writeln( "<TABLE BORDER = \"1\"" + "WIDTH = \"40%\">");

Those two lines should be written as

document.write([
'<h1>Boarding Pass Information<\/h1>',
'<table border="1" width="40%">'
].join("\n"));

Consecutive calls of document.write() are always inefficient and
often error-prone. Especially it is error-prone to
document.writeln( "<TR><TD>" + "<b>" +"NAME:" + "</b>" +
"</TD></TR>" );

write elements separately that only make sense to the markup parser in
combination, such as table-related elements (table, thead, tbody, tfoot,
tr, th, td).


HTH

PointedEars

P.S.
Please provide attribution and trimmed quotes next time:
<URL:http://jibbering.com/faq/faq_notes/pots1.html>
 
W

web.dev

shannon said:
I have been attending classes and trying to figure this out. Can you
help me with this piece, i think the if statement is not executing
properly.

<html>
<HEAD>
<TITLE>Performing Comparisons</TITLE>

<SCRIPT LANGUAGE = "JavaScript">
The language attribute is deprecated, use the type attribute instead:

var passengerName; // first string entered by user
var seatType; // second string entered by user
var classType;


// read first number from user as a string and assigns to var first
passengerName = window.prompt( "Enter your name:", "0" );

// read second number from user as a string and assigns to var
second
seatType = window.prompt( "For First Class type 1 or 2 for
Economy:", "0" );

In regards to this assignment, it seems that you should be placing
those in a form instead of doing a prompt. For example, what would
happen if a user wanted to get 2 or more seats? If I refresh the page,
all data is lost, unless you've learned how to use cookies.
if (seatType ==1){
classType = ("First Class");
}

Place matching closing brace here.

Syntax is case sensitive. That should be a lowercase 'e' instead.
classType=("Economy")};

document.writeln( "<H1>Boarding Pass Information</H1>" );
document.writeln( "<TABLE BORDER = \"1\"" + "WIDTH = \"40%\">");


document.writeln( "<TR><TD>" + "<b>" +"NAME:" + "</b>" +
"</TD></TR>" );


document.writeln( "<TR><TD>" + passengerName +
"</TD></TR>" );


document.writeln( "<TR><TD>" + "<b>" + "SEAT TYPE"+ "</b>" +
"</TD></TR>" );


document.writeln( "<TR><TD>" + seatType+
"</TD></TR>" );


document.writeln( "<TR><TD>" + "<b>" + "CLASS TYPE"+ "</b>" +
"</TD></TR>" );


document.writeln( "<TR><TD>" + classType +
"</TD></TR>" );


document.writeln( "</TABLE>" );

Instead of doing bunch of document.writeln, it would be easier to
create a form and then manipulate the values of the input therein.
 
T

Thomas 'PointedEars' Lahn

shannon said:

Another remark:
if (seatType ==1){
classType = ("First Class");
Else
classType=("Economy")};

You need not enclose any literals (here: string literals) in parentheses.
It will only confuse you when you call your own functions/methods later.

if (seatType == 1)
{
classType = "First Class";
}
else
{
classType = "Economy";
}

And for another thing to think about, find out what the following does:

classType = (seatType == 1) ? "First Class" : "Economy";


Happy coding :)

PointedEars
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Sat, 19 Nov
2005 00:01:57, seen in Thomas 'PointedEars'
Lahn said:
shannon wrote:
if (seatType == 1)
{
classType = "First Class";
}
else
{
classType = "Economy";
}

And for another thing to think about, find out what the following does:

classType = (seatType == 1) ? "First Class" : "Economy";

Neither of those matches the originally stated requirement.
 

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