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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:49:59+00:00 2026-05-27T06:49:59+00:00

I have some javacript that I am trying to implement on an HTML page.

  • 0

I have some javacript that I am trying to implement on an HTML page. The code is below – how can I get it to run as soon as the .html file is opened? It want it to prompt me to enter the weight as soon as i open it.

<script type="text/javascript">
    var weight = parseInt(prompt("What is your weight?"));
    if (weight > 126) {
        alert('Please enter a weight lighter than 126');
    }
    document.writeln('<br/>');
    var wArray = ["fly", "superfly", "bantam", "superbantam", "feather"];

    function recruit() {
        if (0 < weight < 112){
            document.writeln('You are in' + wArray[0] +'class!');
        }
        if (112 < weight < 115){
            alert('You are in' + wArray[1] +'class!');
        }
        if (weight > 115 && weight < 118){
            alert('You are in' + wArray[2] +'class!');
        }
        if(weight > 118 && weight < 122){
            alert('You are in' + wArray[3] +'class!');
        }
        if (weight > 122&& weight < 126){
            alert('Your weight class is' + wArray[4]);
    }
</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-27T06:50:00+00:00Added an answer on May 27, 2026 at 6:50 am

    You have 2 problems with the script:

    • Your recruit() is missing closing bracket }
    • You are not calling recruit() anywhere.

    Several other issues 🙂 :

    • 112 < weight < 115 is not what you want. It will return true even when weight is 1000. It will check if weight is bigger than 112 and then compare if the result is smaller than 115.

    Try:

    var weight = 1000;
    // 112 < 1000 => true, true < 115 => true
    if (112 < weight < 115) { 
       alert("112 < weight < 115");
    }
    
    • You left some values in your checks. If you check for weight < 118 in one if and weight > 118 in another if then what will happen if weight is exactly 118?

    • Use if { } else if { } blocks instead of multiple if-s. In your recruit function even when the weight is 110 and the body of 1st if block is executed, you are still checking the weight in every other if.

    • Add spaces to the output strings, e.g.: 'You are in ' + wArray[0] + ' class! :).

    • As Rocket wrote in the comments: parseInt() should be called with 10 as a 2nd parameter (radix) to force parsing into decimal system. See this.

    • Bonus: Stop using document.writeln as soon as possible as it is teaching you bad practices. For example see this or this.

    HERE is a version addressing these issues.

    Note: The code is executed inside window.onload to make sure that the rest of the document is already loaded so he can access the div.

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

Sidebar

Related Questions

I have some jQuery/JavaScript code that I want to run only when there is
I have some javascript that I'm trying to retool using jQuery to learn the
I have some Javascript code that will programmatically register an COM interop assembly by
I have some JavaScript code that works in IE containing the following: myElement.innerText =
I have some javascript code that creates an img tag with a mouseover callback,
I have some Javascript code that creates 2 arrays: One for Product Category and
I'm working on a project that's trying to implement some editing features using a
I have some javascript that i'm trying to use in a jsf app. I've
I'm trying to implement the following code in a html document: $(function () {
I am trying to implement file upload functionality on my site. I have created

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.