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

  • Home
  • SEARCH
  • 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 8819873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:28:18+00:00 2026-06-14T05:28:18+00:00

I am building a calculator that uses two sliders like this: I have a

  • 0

I am building a calculator that uses two sliders like this:

enter image description here

I have a range of CPU and RAM data that is stored in an object like this:

var CloudPlans = {
   small: {

        id: 'small',

        from: {
            cpu: 1,
            ram: 1
        },

        to: {
            cpu: 2,
            ram: 2
        },

        price: {
            linux: 3490,
            windows: 4190
        }
    },

    medium:  {

        id: 'medium',

        from: {
            cpu: 2,
            ram: 2
        },

        to: {
            cpu: 4,
            ram: 4
        },

        price: {
            linux: 5600,
            windows: 6300
        }

    },

    large: {

        id: 'large',

        from: {
            cpu: 4,
            ram: 4
        },

        to: {
            cpu: 6,
            ram: 8
        },

        price: {
            linux: 9500,
            windows: 10200
        }

    },

           [...more configs here]

}

Now based on the position and value of the slider, I have to check which plan the user has selected and then calculate the price of the components. Here is the function that checks the price range:

    checkPlaninRange: function(cpuVal, ramVal) {
        if(cpuVal >= CloudPlan.small.from.cpu && cpuVal <= CloudPlan.small.to.cpu ) {
            return "small";
        } else if (ramVal >= CloudPlan.small.from.cpu && ramVal <= CloudPlan.small.to.cpu) {
            return "small";
        }
    }

As you can see I will be dealing with almost an endless list of conditionals to return the selected plan. Is there any way to simplify the storage or selection of these plan configs based on code other than conditionals or case statements?

  • 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-14T05:28:19+00:00Added an answer on June 14, 2026 at 5:28 am

    Use an array instead:

    var CloudPlans = [
       {
            id: 'small',
            from: {
                cpu: 1,
                ram: 1
            },
            to: {
                cpu: 2,
                ram: 2
            },
            price: {
                linux: 3490,
                windows: 4190
            }
        },
    
        {
            id: 'medium',
            from: {
                cpu: 2,
                ram: 2
            },
            to: {
                cpu: 4,
                ram: 4
            },
            price: {
                linux: 5600,
                windows: 6300
            }
        },
        {
            id: 'large',
            from: {
                cpu: 4,
                ram: 4
            },
            to: {
                cpu: 6,
                ram: 8
            },
            price: {
                linux: 9500,
                windows: 10200
            }
        },
               //[...more configs here]
    }
    

    Now you can simply iterate over CloudPlans:

    for(int planIdx = 0; planIdx < CloudPlans.length; ++planIdx) {
        var plan = CloudPlan[planIdx];
        if(cpuVal >= plan.from.cpu && cpuVal <= plan.to.cpu  || 
           ramVal >= plan.from.ram && ramVal <= plan.to.ram) {
               return plan.id;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have this calculator I'm building that accepts user variable inputs like let
I am building an html5 calculator that looks like <form onsubmit=return false oninput=o.value =
Situation: I have a calculator that I am building with js. It is a
I am building an application (in vb6) that uses data from a third party
When building an iPhone app that uses the Core Plot framework, I am seeing
I am building an application using OpenCV that uses the webcam and runs some
I'm building a calculator that has a slider. Everytime I slide the bar an
In the webpage I'm building, I have a div that I need to have
Hey everyone I am building a website that needs to have the capability to
I'm building a music recommendation engine that uses the lyrics of a track to

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.