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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:18:21+00:00 2026-06-13T06:18:21+00:00

So i have done this simple task but i don’t see why this is

  • 0

So i have done this simple task but i don’t see why this is not working? Can same one see it and tell me? I see that the problem is that button does not call out the function but why ?

<html>
<head>
    <title>Task count</title>
    <script>
        var over21 = 6.19;
        var under21 = 5.19;

        // Getting data from a user connecting variables with textboxes by ID
        var age = document.getElementById('age');
        var hours = document.getElementById('hours');

        // function wich does all of the calculation
        function magic(){    
            //cheking if he is under or over 21 
            if(age < 21){
                alert("You will make " + (age*under21));
            }else{
                alert("You will make " + (age*over21));                            
            };
        };

        // function that does everything and is connected to the button
        function myFunction(){
            // Validation checking that entered number is not more than 150 
            // And also if age is correct
            if((hours < 150 && hours > 0) && (age < 150 && age > 12)){
                magic();
            }else{
                alert("Wrong!");
            };
        };
  </script>
</head>
<body>
    <label>Enter your age.(12-150)</label>
    <input type="text" class="textBox" id="age"><br>
    <label>Enter how long will you work.(1-150)</label>
    <input type="text" class="textBox" id="hours"><br>
    <button onclick="myFunction()" >How much will i make ?</button>
</body>
</html>​
  • 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-13T06:18:22+00:00Added an answer on June 13, 2026 at 6:18 am

    I would suggest not using so many global variables.

    Move:

    var age = document.getElementById('age');
    var hours = document.getElementById('hours');
    

    into myFunction().

    You’ll then need to make those two:

    var age = parseInt(document.getElementById('age').value);
    var hours = parseInt(document.getElementById('hours').value);
    

    We use parseInt to take the value as a string and turn it into an integer value.

    Since age and hours are now defined in myFunction, you’ll need to pass age to magic()

        var over21 = 6.19;
        var under21 = 5.19;
    
        // function wich does all of the calculation
        function magic(age){
    
          //cheking if he is under or over 21 
           if(age < 21){
                 alert("You will make " + (age*under21));
           }else{
                 alert("You will make " + (age*over21));                            
           };
        };
        // function that does everything and is connected to the button
        function myFunction(){
    
        var age = parseInt(document.getElementById('age').value);
        var hours = parseInt(document.getElementById('hours').value);
         // Validation checking that entered number is not more than 150 // And also if age is correct
         console.log(age + " : " + hours)   
            if((hours < 150 && hours > 0) && (age < 150 && age > 12)){
               magic(age);
            }else{
                alert("Wrong!");
            };
        };
    

    Also, if you want (1-150), you’ll need to modify this if statement:

    if((hours < 150 && hours > 0) && (age < 150 && age > 12)){ ... }
    

    to:

    if((hours <= 150 && hours > 0) && (age <= 150 && age > 12)){ ... }
    

    Lastly, I believe the math may be incorrect in the magic() function:

    function magic(age, hours){
    
      //cheking if he is under or over 21 
       if(age < 21){
             alert("You will make " + (hours*under21));
       }else{
             alert("You will make " + (hours*over21));                            
       };
    };
    

    I believe you wanted hours*under21 and hours*over21. Note that hours is now also being passed in as a parameter.

    EXAMPLE

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

Sidebar

Related Questions

I'm looking for a simple way to have this done. I would to have
I have done this without much effort on T-SQL, but I want to implement
I have done this before but I forgot where in my app I have
I'm currently working on wholesale online t-shirt shop. I have done this for fixed
It's the first time I have done anything like this but wondered what the
i have done some code in jquery but where i commented in this bellow
Math has defeated me once again. This is such a simple task, but I
I have a feeling that I'm missing something simple here but can't seem to
This is super simple task to do in Java but the asynchronous nature of
Ok... I need to do this simple task... I can do it with java

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.