Hi
i currently have this code for an assignment i'm working my way through -
var flightTimes = new Array ('07:15', '08:05', '08:30', '09:30', '09:50', '10:00', '10:20', '10:45', '11:00', '12:00', '13:00', '13:05', '13:15', '13:35', '14:10', '15:00', '16:00', '16:40', '16:55', '17:00', '19:30', '21:00', '22:00', '23:20', '23:59');
-
var flightDestinations = new Array ('Arkham', 'Hensonville', 'Stepford', 'Maycomb', 'Bay Port', 'Denton', 'Waldon City', 'Denton', 'Denton', 'Waldon City', 'Arkham', 'Maycomb', 'Bay Port', 'Stepford', 'Denton', 'Maycomb', 'Waldon City', 'Hensonville', 'Denton', 'Denton', 'Stepford', 'Bay Port', 'Hensonville', 'Waldon City', 'Arkham');
-
var flightOperators = new Array ('Miskatonic', 'SuperSwift', 'Aalto', 'DynaJet', 'Oceanic', 'Aalto', 'Aalto', 'MidSouthCentral Air', 'SuperSwift', 'SuperSwift', 'Miskatonic', 'DynaJet', 'Miskatonic', 'SuperSwift', 'MidSouthCentral Air', 'Aalto', 'SuperSwift', 'Aalto', 'MidSouthCentral Air', 'Aalto', 'DynaJet', 'Oceanic', 'SuperSwift', 'Aalto', 'Miskatonic');
-
var flightFares = new Array (300, 100, 150, 75, 250, 150, 75, 125, 100, 25, 600, 75, 400, 250, 300, 250, 150, 200, 125, 150, 75, 100, 100, 50, 300);
-
-
function displayMessage(aMessage)
-
{
-
document.getElementById('theFlights').innerHTML = aMessage;
-
}
-
-
function showTimetable()
-
{
-
-
for (var i = 0; i <= flightTimes.length; i = i + 1)
-
-
{
-
if (i <= flightTimes.length - 1)
-
{
-
displayMessage((i + 1) + ' ' + flightTimes[i] + ' to ' + flightDestinations[i] + ' operated by ' + flightOperators[i] + '. $' + flightFares[i] + '<BR>');
-
}
-
}
-
-
-
/*for (var i = 0; i <= flightTimes.length; i = i + 1)
-
-
{
-
if (i <= flightTimes.length - 1)
-
{
-
document.write((i + 1) + ' ' + flightTimes[i] + ' to ' + flightDestinations[i] + ' operated by ' + flightOperators[i] + '. $' + flightFares[i] + '<BR>');
-
}
-
}*/
-
-
}
-
-
the trouble i'm having is getting the displayMessage to write down all of the Array's in a <DIV>
it works fine when you do document.write but when you do display message it works it way through the arrays only displaying the last one?
i can't really think of which way to do it if i'm doing it correct in the first place?
any help is much appreciated
z
9 1778
the trouble i'm having is getting the displayMessage to write down all of the Array's in a <DIV>
it works fine when you do document.write but when you do display message it works it way through the arrays only displaying the last one?
i can't really think of which way to do it if i'm doing it correct in the first place?
any help is much appreciated
z
Try - document.getElementById('theFlights').innerHTML += aMessage;
Cool that worked!
i did have a workaround of this -
var myString1 = ('1 ' + flightTimes[0] + ' to ' + flightDestinations[0] + ' operated by ' + flightOperators[0] + '. $' + flightFares[0] + '<BR>' +
-
'2 ' + flightTimes[1] + ' to ' + flightDestinations[1] + ' operated by ' + flightOperators[1] + '. $' + flightFares[1] + '<BR>' +
-
'3 ' + flightTimes[2] + ' to ' + flightDestinations[2] + ' operated by ' + flightOperators[2] + '. $' + flightFares[2] + '<BR>' +
-
'4 ' + flightTimes[3] + ' to ' + flightDestinations[3] + ' operated by ' + flightOperators[3] + '. $' + flightFares[3] + '<BR>' +
-
'5 ' + flightTimes[4] + ' to ' + flightDestinations[4] + ' operated by ' + flightOperators[4] + '. $' + flightFares[4] + '<BR>' );
-
-
var myString2 = ('6 ' + flightTimes[5] + ' to ' + flightDestinations[5] + ' operated by ' + flightOperators[5] + '. $' + flightFares[5] + '<BR>' +
-
'7 ' + flightTimes[6] + ' to ' + flightDestinations[6] + ' operated by ' + flightOperators[6] + '. $' + flightFares[6] + '<BR>' +
-
'8 ' + flightTimes[7] + ' to ' + flightDestinations[7] + ' operated by ' + flightOperators[7] + '. $' + flightFares[7] + '<BR>' +
-
'9 ' + flightTimes[8] + ' to ' + flightDestinations[8] + ' operated by ' + flightOperators[8] + '. $' + flightFares[8] + '<BR>' +
-
'10 ' + flightTimes[9] + ' to ' + flightDestinations[9] + ' operated by ' + flightOperators[9] + '. $' + flightFares[9] + '<BR>' );
-
-
var myString3 = ('11 ' + flightTimes[10] + ' to ' + flightDestinations[10] + ' operated by ' + flightOperators[10] + '. $' + flightFares[10] + '<BR>' +
-
'12 ' + flightTimes[11] + ' to ' + flightDestinations[11] + ' operated by ' + flightOperators[11] + '. $' + flightFares[11] + '<BR>' +
-
'13 ' + flightTimes[12] + ' to ' + flightDestinations[12] + ' operated by ' + flightOperators[12] + '. $' + flightFares[12] + '<BR>' +
-
'14 ' + flightTimes[13] + ' to ' + flightDestinations[13] + ' operated by ' + flightOperators[13] + '. $' + flightFares[13] + '<BR>' +
-
'15 ' + flightTimes[14] + ' to ' + flightDestinations[14] + ' operated by ' + flightOperators[14] + '. $' + flightFares[14] + '<BR>' );
-
-
var myString4 = ('16 ' + flightTimes[15] + ' to ' + flightDestinations[15] + ' operated by ' + flightOperators[15] + '. $' + flightFares[15] + '<BR>' +
-
'17 ' + flightTimes[16] + ' to ' + flightDestinations[16] + ' operated by ' + flightOperators[16] + '. $' + flightFares[16] + '<BR>' +
-
'18 ' + flightTimes[17] + ' to ' + flightDestinations[17] + ' operated by ' + flightOperators[17] + '. $' + flightFares[17] + '<BR>' +
-
'19 ' + flightTimes[18] + ' to ' + flightDestinations[18] + ' operated by ' + flightOperators[18] + '. $' + flightFares[18] + '<BR>' +
-
'20 ' + flightTimes[19] + ' to ' + flightDestinations[19] + ' operated by ' + flightOperators[19] + '. $' + flightFares[19] + '<BR>' );
-
-
var myString5 = ('21 ' + flightTimes[20] + ' to ' + flightDestinations[20] + ' operated by ' + flightOperators[20] + '. $' + flightFares[20] + '<BR>' +
-
'22 ' + flightTimes[21] + ' to ' + flightDestinations[21] + ' operated by ' + flightOperators[21] + '. $' + flightFares[21] + '<BR>' +
-
'23 ' + flightTimes[22] + ' to ' + flightDestinations[22] + ' operated by ' + flightOperators[22] + '. $' + flightFares[22] + '<BR>' +
-
'24 ' + flightTimes[23] + ' to ' + flightDestinations[23] + ' operated by ' + flightOperators[23] + '. $' + flightFares[23] + '<BR>' +
-
'25 ' + flightTimes[24] + ' to ' + flightDestinations[24] + ' operated by ' + flightOperators[24] + '. $' + flightFares[24] + '<BR>' );
-
-
displayMessage(myString1 + '<BR>' + myString2 + '<BR>' + myString3 + '<BR>' + myString4 + '<BR>' + myString5);
-
is there anything i could insert to put a gap every 5 lines? ie -
if (flightTimes[i] == 5)
-
{
-
<BR>
-
}
-
on Adding the + sign to the code everything i click a link button the text never clears the screen it just keeps adding to it? is this right
z
on Adding the + sign to the code everything i click a link button the text never clears the screen it just keeps adding to it? is this right
Yup. If you want to clear the text from it, put a line similar to this one before your loop executes: -
var $theFlights = document.getElementById('theFlights');
-
while($theFlights.firstChild)
-
$theFlights.removeChild($theFlights.firstChild);
-
Is there no way in which this can be done without chaing the actual function as it's used for other tasks?
z
Is there no way in which this can be done without chaing the actual function as it's used for other tasks?
z
You mean showTimetable()? Does it matter if "theFlights" div is cleared before you show the timetable?
is there anything i could insert to put a gap every 5 lines? ie -
if (flightTimes[i] == 5)
-
{
-
<BR>
-
}
-
% is the modulus operator. It gives the remainder.
What i mean is the there no way in doing this without chaning the function displayMessage? -
-
function displayMessage(aMessage)
-
{
-
document.getElementById('theFlights').innerHTML = aMessage;
-
}
-
-
Just define and call another function if you don't want to change the function.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Anand Pillai |
last post by:
This is for folks who are familiar with asynchronous event handling in
Python using the asyncore module.
If you have ever used the asyncore module, you will realize that it's
event loop does not...
|
by: Rhamphoryncus |
last post by:
First a bit about myself. I've been programming in python several
years now, and I've got several more years before that with C. I've
got a lot of interest in the more theoretical stuff (language...
|
by: hall |
last post by:
Hi.
I've come across someting strange. I was trying to make a for-loop
execute repetadly until the function called inside it does not return
true during the entire loop (see program below).
...
|
by: na1paj |
last post by:
here's a simple linked list program. the DeleteNode function is
producing an infinit loop i think, but i can't figure out where..
#include <stdio.h>
typedef struct
{
char *str; //str is a...
|
by: Ed Jay |
last post by:
<disclaimer>New to js.</disclaimer>
I have several pages, each with menues comprising checkboxes or radio
boxes within the same form. I presently 'brute force' clear the buttons
with individual...
|
by: gmou |
last post by:
Dear group,
I am building a translator from C++ into VB (and into C#).
At the moment, I have a hard time figuring out the equivalent of a 'for'
loop in VB.
Given C++ code:
for( int i=0;...
|
by: MicroMoth |
last post by:
Hi,
I'm trying to call a Javascript function within a foreach loop. I am loop
over a series of users and I want to call the JS function which opens a new
window, passing in the user id to each...
|
by: hufaunder |
last post by:
I have 16-bit data that I want to display. In order to display it I
compress a certain range of the input data into 8 bit (I need control
over this). All seems to work ok except that it is dead...
|
by: mrjoka |
last post by:
hi experts,
i'm developing a page in ASP but i'm doing also some javascript insode the page. i'm creating a frame and i want to loop this frame with a duplicateloop function so the form will be...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
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,...
|
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...
| |