Hello guys! im a newbie in programming and i need help..Anyone familiar with array??below is the case and i hope someone can help me.. thx..

Write a program to assign seats on each flight of the airline’s only plane (capacity: 20 seats). Your program should display the following menu of alternatives: Please type 1 for "Business" and Please type 2 for "Economy". If the person types 1, your program should assign a seat in the first-class section (seats 1–10). If the person types 2, your program should assign a seat in the economy section (seats 11–20). Your program should print a boarding pass indicating the person’s seat number and whether it is in the first-class or economy section of the plane.

Use a one-dimensional array to represent the seating chart of the plane. Initialize all the elements of the array to 0 to indicate that all seats are empty. As each seat is assigned, set the corresponding elements of the array to 1 to indicate that the seat is no longer available.

Your program should never assign a seat that has already been assigned.

Well, start coding. If you have a problem post again, with your code and a description of your problem, along with any error messages (complete) and we will help, but we are not going to write it for you.

Hi again..this is what i do so far..
but there is still a problem, bcos my teacher told me that the seats must be randomly assigned..So for example, user choose Business, then the seats go random between 1 to 5..

<?xml version = "1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<!-- Solution11.16 -->
<!-- Airline Reservation System-->

<html xmlns = "http://www.w3.org/1999/xhtml">

    <head>
        <title>Airline Reservation System</title>

        <script type = "text/javascript">
        <!--

        var input;
        var secondInput;
        var element;
        var secondElement;
        var firstCount = 0;
        var economyCount = 0;
        var seats = [ ,0,0,0,0,0,0,0,0,0,0];            //allocate 10-element Array

        function startArray()
        {


            for(var i=0; i<11; i++)
            {

                    input = window.prompt("Please type 1 for First Class and Please type 2 for Economy.","0");

                    if (input == 1 || input == 2)
                    {
                        element = linearSearch(seats);
                        if (element==-1 && input == 1)
                        {
                            document.writeln("The First Class is already fully booked<br/>");
                            secondQuestion(seats);
                        }
                        else if (element ==-1 && input == 2)
                        {
                            document.writeln("The Economy Class is already fully booked<br/>");
                            secondQuestion(seats);
                        }
                        else
                            boardingPass(input);    
                    }


                    //to terminate the program
                    else 
                    {
                        window.status = "Bye-bye!";
                        System.exit(0);
                    }


            }
        }

        function linearSearch(theArray)
        {
            if (input == 1)
            {
                for (var n=0; n<6 ; n++)
                    if (theArray [n] == 0)
                        return n;
            }
            else if (input == 2)
            {
                for (var n=6; n<11 ; n++)
                    if (theArray [n] == 0)
                        return n;
            }
            return -1;
        }

        function boardingPass(theInput)
        {
            if (input ==1)
            {    
                document.writeln("----------BOARDING PASS----------<br/>");
                document.writeln("You are allocated in the First Class<br/>");
                document.writeln("Your seat number is "+ element+"<br/>");
                 document.writeln("-----------------------------------------<br/>");
                seats[element]= 1;
                firstCount++;    
            }
            else if (input ==2)
            {    
                document.writeln("----------BOARDING PASS----------<br/>");
                document.writeln("You are allocated in the Economy Class<br/>");
                document.writeln("Your seat number is "+ element +"<br/>");
                document.writeln("-----------------------------------------<br/>");
                seats[element]= 1;
                economyCount++;    
            }

        }

        function secondQuestion(theArray)
        {
            if (input == 1)
            {
                for (var n=6; n<11 ;n++)
                {
                    if (theArray [n] == 0)
                    {
                        secondInput = window.prompt("Do you want to move to Economy Class? (If YES, please press 1. If NO, please press 2)","0");
                            if ( secondInput == 1)
                            {

                                input = 2;
                                element=linearSearch(seats);
                                document.writeln("You have been allocated to Economy Class<br/>");
                                boardingPass(input);
                                break;
                            }
                            else if (secondInput == 2)
                            {
                                document.writeln("Next flight leaves in 3 hours<br/>");
                                break;
                            }
                    }
                }
            }
            else if (input == 2)
            {
                for (var n=0; n<6 ;n++)
                {
                    if (theArray [n] == 0)
                    {
                        secondInput = window.prompt("Do you want to move to First Class? (If YES, please press 1. If NO, please press 2)","0");
                            if ( secondInput == 1)
                            {
                                input = 1;
                                element=linearSearch(seats);
                                document.writeln("You have been allocated to First Class<br/>");
                                boardingPass(input);
                                break;
                            }
                            else if (secondInput == 2)
                            {
                                document.writeln("Next flight leaves in 3 hours<br/>");
                                break;
                            }
                    }
                }
            }

        }


        //-->
        </script>

    </head>
    <body onload = "startArray()"></body>
</html>
<?xml version = "1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<!-- Solution11.16 -->
<!-- Airline Reservation System-->

<html xmlns = "http://www.w3.org/1999/xhtml">

    <head>
        <title>Airline Reservation System</title>

        <script type = "text/javascript">
        <!--
        
        var input;
        var secondInput;
        var element;
        var secondElement;
        var firstCount = 0;
        var economyCount = 0;
        var seats = [ ,0,0,0,0,0,0,0,0,0,0];            //allocate 10-element Array
        
        function startArray()
        {
            

            for(var i=0; i<11; i++)
            {
                
                    input = window.prompt("Please type 1 for First Class and Please type 2 for Economy.","0");

                    if (input == 1 || input == 2)
                    {
                        element = linearSearch(seats);
                        if (element==-1 && input == 1)
                        {
                            document.writeln("The First Class is already fully booked<br/>");
                            secondQuestion(seats);
                        }
                        else if (element ==-1 && input == 2)
                        {
                            document.writeln("The Economy Class is already fully booked<br/>");
                            secondQuestion(seats);
                        }
                        else
                            boardingPass(input);    
                    }
                    
                    
                    //to terminate the program
                    else 
                    {
                        window.status = "Bye-bye!";
                        System.exit(0);
                    }
                    
                    
            }
        }
        
        function linearSearch(theArray)
        {
            if (input == 1)
            {
                for (var n=0; n<6 ; n++)
                    if (theArray [n] == 0)
                        return n;
            }
            else if (input == 2)
            {
                for (var n=6; n<11 ; n++)
                    if (theArray [n] == 0)
                        return n;
            }
            return -1;
        }

        function boardingPass(theInput)
        {
            if (input ==1)
            {    
                document.writeln("----------BOARDING PASS----------<br/>");
                document.writeln("You are allocated in the First Class<br/>");
                document.writeln("Your seat number is "+ element+"<br/>");
                 document.writeln("-----------------------------------------<br/>");
                seats[element]= 1;
                firstCount++;    
            }
            else if (input ==2)
            {    
                document.writeln("----------BOARDING PASS----------<br/>");
                document.writeln("You are allocated in the Economy Class<br/>");
                document.writeln("Your seat number is "+ element +"<br/>");
                document.writeln("-----------------------------------------<br/>");
                seats[element]= 1;
                economyCount++;    
            }
            
        }

        function secondQuestion(theArray)
        {
            if (input == 1)
            {
                for (var n=6; n<11 ;n++)
                {
                    if (theArray [n] == 0)
                    {
                        secondInput = window.prompt("Do you want to move to Economy Class? (If YES, please press 1. If NO, please press 2)","0");
                            if ( secondInput == 1)
                            {
                                
                                input = 2;
                                element=linearSearch(seats);
                                document.writeln("You have been allocated to Economy Class<br/>");
                                boardingPass(input);
                                break;
                            }
                            else if (secondInput == 2)
                            {
                                document.writeln("Next flight leaves in 3 hours<br/>");
                                break;
                            }
                    }
                }
            }
            else if (input == 2)
            {
                for (var n=0; n<6 ;n++)
                {
                    if (theArray [n] == 0)
                    {
                        secondInput = window.prompt("Do you want to move to First Class? (If YES, please press 1. If NO, please press 2)","0");
                            if ( secondInput == 1)
                            {
                                input = 1;
                                element=linearSearch(seats);
                                document.writeln("You have been allocated to First Class<br/>");
                                boardingPass(input);
                                break;
                            }
                            else if (secondInput == 2)
                            {
                                document.writeln("Next flight leaves in 3 hours<br/>");
                                break;
                            }
                    }
                }
            }
            
        }


        //-->
        </script>

    </head>
    <body onload = "startArray()"></body>
</html>

JavaScript != Java.

Please find a JavaScript forum and post your question there.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.