Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

storing data in arrays

shannondingleshannondingle Member Posts: 10
Hi,
Can anyone tell me whats wrong with my code. Thanks




Airline Booking



var myairline = new Array(10);
var first = 0;
var economy = 5;
var name;
var class;






Comments

  • NCS_OneNCS_One Member Posts: 170
    Hi

    1 - You have to replace the var class it seems that its already in use.

    2 - This line - document.write(myairline[i] ++ "
    ") - should be
    document.write(myairline[i] + "
    ") with only one +.

    3 - You have an Array named array i dont no if it should be the myairline array or is it a new one and if so you have to declare it.

    I think there is more errors but i dont know what you are trying to do.

    Hope it helps.
    Any more question just ask.
  • shannondingleshannondingle Member Posts: 10
    Hi
    thanks for that, as you say there are more errors. It is a airline reservation system i'm trying to do. I need to ask the user their name and whether they require a first class seat or economy. There are only 10 seats in total 5 for each class. I then need to output the passenger info onto the screen. I also have constraints if first class is full i need to ask whether economy is ok.



    : Hi
    :
    : 1 - You have to replace the var class it seems that its already in use.
    :
    : 2 - This line - document.write(myairline[i] ++ "
    ") - should be
    : document.write(myairline[i] + "
    ") with only one +.
    :
    : 3 - You have an Array named array i dont no if it should be the myairline array or is it a new one and if so you have to declare it.
    :
    : I think there is more errors but i dont know what you are trying to do.
    :
    : Hope it helps.
    : Any more question just ask.
    :

  • CyGuyCyGuy Member Posts: 312
    : Hi,
    : Can anyone tell me whats wrong with my code. Thanks
    :
    :
    Hi Shannon Dingle,
    I remember you. you should have continued this post on the original page you created. Here is a little help... should get you going. Hope you don't mind that I slaughtered your code:)
    [code]
    :
    :
    : Airline Booking
    :
    :
    :
    : var myairline = new Array(10);
    : var first = 0;
    : var economy = 5;
    : var name;
    : var class;
    :
    :
    :
    :
    [/code]
    :
    :
    :

    I have class, but if you review this and post your new code, I will be glad to assist further. until(then)


    [green]WHAT you;see_is_what=you.get;[/green]
    -Russ aka DangeRuss

  • shannondingleshannondingle Member Posts: 10
    Hi,
    Thanks for the help, window.prompt was better idea. I have the modification that you suggested however, I'm not sure if i have changed the bottom half of the code properly. Where first++ is swapped for economy++. I have included my code.
    *******New Version***********************




    Airline Booking



    var myairline = new Array(10);
    var first = 0;
    var economy = 5;
    var name;
    var classType;
    var ask;
    var askme;






    ***************end**********************












    : : Hi,
    : : Can anyone tell me whats wrong with my code. Thanks
    : :
    : :
    : Hi Shannon Dingle,
    : I remember you. you should have continued this post on the original page you created. Here is a little help... should get you going. Hope you don't mind that I slaughtered your code:)
    : [code]
    : :
    : :
    : : Airline Booking
    : :
    : :
    : :
    : : var myairline = new Array(10);
    : : var first = 0;
    : : var economy = 5;
    : : var name;
    : : var class;
    : :
    : :
    : :
    : :
    : [/code]
    : :
    : :
    : :
    :
    : I have class, but if you review this and post your new code, I will be glad to assist further. until(then)
    :
    :
    : [green]WHAT you;see_is_what=you.get;[/green]
    : -Russ aka DangeRuss
    :
    :

  • CyGuyCyGuy Member Posts: 312
    [green]Hey, it isn't a problem; i am learning Jscript as well, however i have some experience with programming.
    i hope you don't mind, but i will remove comments, because too many of them make reading code difficult.
    You also need to do as NCS One said:[/green]
    "Hi

    1 - You have to replace the var class it seems that its already in use.

    2 - This line - document.write(myairline[i] ++ "
    ") - should be
    document.write(myairline[i] + "
    ") with only one +.

    3 - You have an Array named array i dont no if it should be the myairline array or is it a new one and if so you have to declare it.

    I think there is more errors but i dont know what you are trying to do.

    Hope it helps.
    Any more question just ask."
    [green]you must be consistant with the use of variables. you can not use array[] and myairline[] for the same thing.
    that's redundant (a bad word in programming)
    [/green]
    : Hi,
    : Thanks for the help, window.prompt was better idea. I have the modification that you suggested however, I'm not sure if i have changed the bottom half of the code properly. Where first++ is swapped for economy++. I have included my code.
    : *******New Version***********************
    :
    :[code]
    :
    :
    : Airline Booking
    :
    :
    :
    : var myairline = new Array(10);
    : var first = 0;
    : var economy = 5;
    : var name;
    : var classType;
    : var ask;
    : var askme;
    :
    :
    :
    :
    :
    [/code]
    :
    : ***************end**********************
    :
    :
    [blue]
    You may still find errors, but if you do everything that you have been shown it will have sound logic.
    someone can help with the syntax errors, or
    if using IE do this, and it will tell where errors are:
    1. click on Tools at top of internet explorer
    2. click on Internet Options
    3. at the top of the pop-up there is an Advanced tab -click it
    4. check Display a notification about every script error
    5. click Apply button
    6. close pop-up
    [green]now when you run the program it will do more than nothing. if you have errors you will know where to find them[/green]
    let us know if you have any more problems, someone will be here to lend a helping hand
    good luck[/blue]
  • shannondingleshannondingle Member Posts: 10
    Hi,
    I have made the suggested changes and my code now works!! Thanks.

    1. I think a while loop would be good idea as i want to be able ask many users their flight preferences. At the moment my program only asks the user once for their details and outputs this info to the screen. Any suggestions?
    While (first !=4 && economy !=9) {
    }
    Would this be right?


    2. If the user presses cancel should i want to break.
    If (name== null){
    break;
    }

    Shannon

    : [green]Hey, it isn't a problem; i am learning Jscript as well, however i have some experience with programming.
    : i hope you don't mind, but i will remove comments, because too many of them make reading code difficult.
    : You also need to do as NCS One said:[/green]
    : "Hi
    :
    : 1 - You have to replace the var class it seems that its already in use.
    :
    : 2 - This line - document.write(myairline[i] ++ "
    ") - should be
    : document.write(myairline[i] + "
    ") with only one +.
    :
    : 3 - You have an Array named array i dont no if it should be the myairline array or is it a new one and if so you have to declare it.
    :
    : I think there is more errors but i dont know what you are trying to do.
    :
    : Hope it helps.
    : Any more question just ask."
    : [green]you must be consistant with the use of variables. you can not use array[] and myairline[] for the same thing.
    : that's redundant (a bad word in programming)
    : [/green]
    : : Hi,
    : : Thanks for the help, window.prompt was better idea. I have the modification that you suggested however, I'm not sure if i have changed the bottom half of the code properly. Where first++ is swapped for economy++. I have included my code.
    : : *******New Version***********************
    : :
    : :[code]
    : :
    : :
    : : Airline Booking
    : :
    : :
    : :
    : : var myairline = new Array(10);
    : : var first = 0;
    : : var economy = 5;
    : : var name;
    : : var classType;
    : : var ask;
    : : var askme;
    : :
    : :
    : :
    : :
    : :
    : [/code]
    : :
    : : ***************end**********************
    : :
    : :
    : [blue]
    : You may still find errors, but if you do everything that you have been shown it will have sound logic.
    : someone can help with the syntax errors, or
    : if using IE do this, and it will tell where errors are:
    : 1. click on Tools at top of internet explorer
    : 2. click on Internet Options
    : 3. at the top of the pop-up there is an Advanced tab -click it
    : 4. check Display a notification about every script error
    : 5. click Apply button
    : 6. close pop-up
    : [green]now when you run the program it will do more than nothing. if you have errors you will know where to find them[/green]
    : let us know if you have any more problems, someone will be here to lend a helping hand
    : good luck[/blue]
    :

  • CyGuyCyGuy Member Posts: 312
    : Hi,
    : I have made the suggested changes and my code now works!! Thanks.
    :
    : 1. I think a while loop would be good idea as i want to be able ask many users their flight preferences. At the moment my program only asks the user once for their details and outputs this info to the screen. Any suggestions?
    : While (first !=4 && economy !=9) {
    : }
    : Would this be right?
    :
    :
    : 2. If the user presses cancel should i want to break.
    : If (name== null){
    : break;
    : }
    :
    [green]this is a question for your teacher, as I don't know what he wants. both are fine. in actual practice, break is frowned upon... like goto. this is especially important in functions, where you should use return instead, and the MAIN loop. in other languages running in windows, the main loop is a function that runs under windows... windows requires a seperate function to be call to close the application properly, however you need not concern yourself with this in javascript, because the explorer handles this for you.

    as far as loops go there are many variants, as i am sure you are aware, but consider these 2:
    1. REPEAT..UNTIL
    [code]while(condition){
    needs a condition to enter loop
    }
    [/code]
    2. DO..LOOP
    [code]do{
    will execute no matter what
    }while(condition)
    [/code]
    they are the same in many ways, excep for the placement of the condition. In top down fashion, 1 will not enter unless the condition is met and will not exit until it is changed 2 will always run once and if the condition is met it will exit, otherwise it shall continue

    as you continue to program you will find more uses for these conditions. when i am not busy coding, i look for ways to keep learning these techniques. so, i enjoy the experience of going over other peoples assignments with them.

    see ya next time,
    russ
Sign In or Register to comment.