Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7445077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:43:50+00:00 2026-05-29T11:43:50+00:00

Yet again another assignment I need help on. All i need is just the

  • 0

Yet again another assignment I need help on. All i need is just the work checked over and tell me why the items in the first array aren’t working properly to the corresponding number the user enters.

Directions:

Create a new file named a5_yourname.html. Use the steps below to write a script that will prompt the user for two numbers. One will give the type of bread chosen the other the type of filling chosen for a sandwich.

Use these choices to display a statement that will extract the correct name of bread and filling from the perspective arrays to send an alert message to the user. Use the variable names and messages as they are described in the steps.

A. Create an array named “breadArray”. Enter the following values into the breadArray: white, wheat, rye, wrap

B. Create a second array named “fillingArray”. Enter the following values in the fillingArray: ham, turkey, egg salad, beef, peanut butter

C. Use a prompt to tell the user what types of bread there are, giving them each a number and ask them to choose bread by the number.

Like:
Bread choices are: 1 for white, 2 for wheat, 3 for rye and 4 for a wrap.
Please select the type of bread for your sandwich using a number from 1 to 4.

D. Use an “if”- “else” statement and the “isNaN” function to determine if the user entered a number. Test if the number are within range. If they did not enter a valid number display an alert message box asking them to enter a number. Repeat this step after step “F” as well.

E. Save the number given in a variable named “breadChoice”.

F. Use a prompt to tell the user what types of fillings there are, giving them each a number and ask them to choose a filling by the number.
Like:
Filling choices are: 1 for ham, 2 for turkey, 3 egg salad, 4 beef, and 5 peanut butter
Please select the type of filling for your sandwich using a number from 1 to 5.

G. Save the number given in a variable named “fillingChoice”.

H. If the user entered a valid number then use the numbers given by the user to extract the correct bread and filling, from the appropriate array, for the sandwich and display the following message using the document.write statement:

“I will order you a “name of filling” on “name of bread” sandwich for lunch.”
Example: If the user enters 1 for bread and a 2 for filling then the message should read:
I will order you a ham on wheat sandwich for lunch.

My Code:

<head>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <title>Assignment 5: Arrays</title>

    <script type="text/javascript">

        // Variable Declarations

            var breadArray = new Array ("white","wheat","rye","wrap");
            var fillingArray = new Array ("ham","turkey","egg salad","beef","peanut butter")
            var breadChoice;
            var fillingChoice;

        // Assignments

            breadChoice = Number(prompt("Bread choices are: 1 for White, 2 for Wheat, 3 for Rye, or 4 for a Wrap. Please select the type of bread for you sandwich using a number from 1 to 4"),0)-1;
            fillingChoice = Number(prompt("Filling choices are: 1 for ham, 2 for turkey, 3 egg salad, 4 beef, or 5 peanut butter. Please select the type of filling for your sandwich using a number from 1 to 5"),0)-1;

        // Calculations

            // none


        // Output


        if (breadArray[breadChoice] && fillingArray[fillingChoice])
        {
         alert("Thanks! I am now calculating your sandwich order.");
        }
        else
        { 
            alert("Sorry. You did not enter a correct numeric value, please try again!");
        }



        document.write("I will order you a &nbsp;" +fillingArray[fillingChoice] +"&nbsp; on &nbsp;" +breadArray[breadChoice] +"&nbsp; sandwich for lunch");

    </script>

</head>

<body>

</body>

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T11:43:52+00:00Added an answer on May 29, 2026 at 11:43 am

    the error is that it sometimes says undefined for the filling choice when i enter a valid number.

    This will happen if the user enters 4 when propmted for breadChoice, since breadArray[4] is effectively undefined (the fourth and last element is breadArray[3]).

    To prevent this from happening, you could use:

    breadChoice = Number(...) - 1;
    

    I think the problem is my if, else statement actually.

    No, but it isn’t right nonetheless. Your if-else statement will execute alert("Thanks!...); in the first and second case, but in each only one condition gets validated. I suggest using

    if (breadArray[breadChoice] && fillingArray[fillingChoice])
        alert("Thanks! I am now calculating your sandwich order.");
    else 
        alert("Sorry. You did not enter a correct numeric value, please try again!");
    

    which will simply test if breadArray[breadChoice] and fillingArray[fillingChoice] are defined.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Yet another newbie with ASP.NET MVC! All I intend to do is for a
I've just added yet another 3rd-party component to my .net project that contains a
First, I am NOT trying to spur yet another debate about LINQ vs. stored
Yet again another issue with resizing, like many others I have used the CreateParams
Back again with yet another DirectSound question, this one regarding the ways DirectSound Buffers
Yet another question. So now my EventReceiver and its logic is working just fine.
Yet again, my teacher was unable to answer my question. I knew who may
I'm going to rebuild my Linux box [yet] again. I have to create a
Anybody found yet a good web site architecture using linq to sql? Any help
My apologies once again for asking another very junior question. For one reason or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.