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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:31:24+00:00 2026-06-10T00:31:24+00:00

For some reason after the if, it continues to else, except the ifs that

  • 0

For some reason after the if, it continues to else, except the ifs that take you to a different place, here is the code i have at the moment

<script type="text/javascript">
    function whatname(button) {
        var post = prompt("Name?", "Visitor")
        if(post == "Nick"){
            alert("Hi Nick")
            window.location = "index.html"
        }
        if(post == "Visitor"){
            alert("Welcome Visitor")
            window.location = "index.html"
        }
        if(post == ""){
            alert("Please Enter Name")
        }
        if(post == null){
            alert("Closing")
        }
        if(post == "show me a secret"){
            window.location = "secret.html"
        }
        if(post == "Greg"){
            alert("Test")
        }
        if(post == "greg"){
            alert("Test 1")
        }
        else{
            alert("Welcome " + post + ", Have Fun!")
            window.location = "index.html"
        }
    }
</script>

After the if happens, it continues to else, like let say i click cancel (which would be null) it would say, “Closing” but than another pop up would come up and would say, “Welcome Null, Have Fun!” than it would take me somewhere else, im not sure whats wrong, if you can help, it would be nice.

  • 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-06-10T00:31:25+00:00Added an answer on June 10, 2026 at 12:31 am

    use else if rather than if

    if(condition 1) {
    } else if(condition 2) {
    } else {
    }
    

    What’s happening now is that it is first checking if post is “Nick”. Regardless of whether or not it is, it will move on to check if post is “Visitor”. This is of course not what you want. You only want to perform the second test if the first one was found to be false.

    As written, only the very last if statement has an else. You will get the “Welcome, have fun”-message whenever post is anything but greg.

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

Sidebar

Related Questions

For some reason there's a variable called d that is defined immediately after I
For some reason, after installing the iPhone OS 3.0 SDK, I have no option
If we have a method: public void doSomething(){ synchronized(this){ //some code processing here }
I'm running mod_wsgi on apache2. It's running Django and for some reason, after I
Is there a specific reason why some people put a semicolon after the curly
For some reason, this line of code is returning undefined for $(this).attr(href) $(a).attr(href, javascript:page('
For some reason the postback event keeps firing for my button. If I place
I have a faulty hard drive that works intermittently. After cold booting, I can
I have a WCF service that sometimes has to return a Fault. For some
I'm new to writing switch statements after learning about it yesterday. For some reason,

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.