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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:38:58+00:00 2026-05-30T09:38:58+00:00

I am getting multiple user inputs stored in a object, called inputObj, these properties

  • 0

I am getting multiple user inputs stored in a object, called inputObj, these properties then need to all be ranked out of 100, (attached is the current method for ranking one property), need to do this for up to 20 properties, so currently this is a method where im repeating myself alot.

The maths is all working fine and im gettign the wanted outputs, but need a tidier way to do this, suggestions?

The main issue is that the mathematical manipulations will change for each property, so a universal function applying to all the properties wont work

Thanks

if (inputObj.dyAGE <=5) {
    inputObj.dyAGE *= 5.5;  
    }       
else if (inputObj.dyAGE<=7) {
    inputObj.dyAGE -= 5;
    inputObj.dyAGE *= 16.5;
    inputObj.dyAGE += 33;       
    }
else if(inputObj.dyAGE<=11) {
    inputObj.dyAGE -= 7;
    inputObj.dyAGE *= 8.25;
    inputObj.dyAGE += 66;
    }
else if (inputObj.dyAGE<=16) {
    inputObj.dyAGE -= 17;
    inputObj.dyAGE = -inputObj.dyAGE;
    inputObj.dyAGE *= 6.6;
    inputObj.dyAGE += 66;       
    }   
else if(inputObj.dyAGE <= 19) {
    inputObj.dyAGE -= 20;
    inputObj.dyAGE = -inputObj.dyAGE;
    inputObj.dyAGE *= 11;
    inputObj.dyAGE += 33
    }   
else if (inputObj.dyAGE <= 30) {
    inputObj.dyAGE-31;
    inputObj.dyAGE = -inputObj.dyAGE;
    inputObj.dyAGE *= 3;
};
  • 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-30T09:39:00+00:00Added an answer on May 30, 2026 at 9:39 am

    You could use a Function:

    inputObj.dyAGE = convert_AGE(inputObj.dyAGE)
    
    function convert_AGE(x) {
    
        if (x <= 5)
            return x * 5.5;  
        if (x <= 7)
            return (x - 5) * 16.5 + 33;
        etc
    

    Also you can convert series of assignments (inputObj.dyAGE=...) into expressions, so that this

    inputObj.dyAGE -= 17;
    inputObj.dyAGE = -inputObj.dyAGE;
    inputObj.dyAGE *= 6.6;
    inputObj.dyAGE += 66;      
    

    becomes this

    (17 - x) * 6.6 + 66
    

    or even

    178.2 - 6.6 * x
    

    Of course, you can use distinct functions for each property, like

          inputObj.dyAGE = convert_AGE(inputObj.dyAGE)
          inputObj.dyXYZ = convert_XYZ(inputObj.dyXYZ)
    

    or automate this by creating a hash of functions:

       convertors = {
             'dyAGE': function(x) { code to convert age },
             'dyXYZ': function(x) { code to convert xyz },
              etc
        }
    

    and then convert all properties at once

        for (var prop in input)
            if (prop in convertors)
                input.prop = convertors[prop](input.prop);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page with user controls getting dynamically added. Inside some of these
I created stored proc so that user can select multiple comma separated values into
I previous recieved help with a problem, getting a multiple option select form to
I keep getting errors that my functions have been defined multiple times. Of course
Can multiple SSRS share the same DB? We're getting into an SSRS customization scenario,
Getting a rendering error for this form: 'NoneType' object has no attribute 'widget' http://dpaste.com/88585/
I need a means of getting past Firefox's irritating refusal to pass the full
My controllers are getting large and out of hand. A typical controller does the
I have a bash script which prompts for user input multiple times and processes
I wanted to read input from user (multiple lines) and write it into a

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.