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 7403827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:09:59+00:00 2026-05-29T05:09:59+00:00

I have an assignment for Javascript class. The basis of the assignment is to

  • 0

I have an assignment for Javascript class. The basis of the assignment is to use the if/else if statements to set up the script. I’ve read and re-read the assignment and I don’t understand how to get the names (user input) in alphabetical ordering. Please help!My instructor and book are useless! Here are the instructions:

Write the JavaScript code in one HTML document using IF, and IF/Else statements for the following three situations. For each one make sure to write comments for each section.

B. Check for the alphabetical order of names.

(See ASCII table at http://www.asciitable.com/ to confirm)

Variable declarations section
1. Declare a variable that holds a person’s last name.
2. Declare a variable that holds a second person’s last name.

Assignments section
3. Ask the user to enter their last name.
4. Ask the user to enter the last name of a friend.

Logic and Output section
5. Use only variables in your logic.
6. Determine which name is first in the ascending sequence of the alphabet.
7. Display the message “Your last name is before/after mine in the alphabet.”

Testing: Try names that have the same first letter. Compare names where one begins with a small letter and the other a capital letter. Compare names that are close with one letter different like: Anderson and Andersen.

My code thus far:

    <script type="text/javascript">

        // Variable declarations

            var userLast1;          
            var userLast2;

       // Assignments

        userLast1 = prompt("Please enter your last name.");
        userLast2 = prompt("Please enter the last name of a friend.");

       // Calculations & output

       if (userLast1 > userLast2)
       {
       alert("Your last name comes before your friend's in the alphabet.");
       }
       else if (userLast2 > userLast1)
       {
       alert("Your friend's last name comes before your's in the alphabet.");
       }
       else
       {
       alert("You and your friend have the same last name.");
       }


    </script>
  • 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-29T05:10:00+00:00Added an answer on May 29, 2026 at 5:10 am

    You can compare the strings with < and friends. All you need to do is (in pseudocode):

    if str1 is less than str2
        output "first string is less than second string"
    else
        output "second string is less than first string"
    

    The only gotcha here is that "B"<"a" returns true, which may be intended behavior.

    As far as your code is concerned, you do not want to use parseFloat. Think about (or google) what parseFloat does. What do you think will happen when you pass someone’s last name (that doesn’t include any digits) into parseFloat, and is that the behavior you want?

    If you need help with the syntax of if statements, here is an example:

    if (1 < 2) {
        alert("1 is less than 2.  Who knew?");
    } else {
        alert("This really should not be reached, since 1 is less than 2");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The basis of the assignment is to use the if/else if statements to set
I have an assignment in a language-independent class, and part of it is using
We have just started our new assignment - web-based project. Before I get directly
I have a conflict when I use a jquery script for inline window and
Any Javascript ninjas or people who have read ECMA-262 5th care to explain the
I have an issue with meeting XHTML Strict requirements for a class assignment. The
I have this assignment to read, write, enable cookies so that the username will
I'm doing a javascript assignment and have just learned that I can do it
Is it possible to have assignment in a condition? For ex. if (a=some_func()): #
I have an assignment to create a GUI using MATLAB GUIDE and am having

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.