0

I am trying to create a simple script to add to a html website.

I need it to calculate the price based on the quantity the user inputs.

For example, a value of 1-1000 will be multiplied by 1.50 and displayed, 1001-5000 multiplied by 1.20 and displayed, 5001-10000 multiplied by 1 and displayed and any number above that would display an error message like "Must be below 10000".

The result is to display in a text field so the user can click submit.

I've been trying to do this in js with no success. If this can be done in any other language please let me know. I'm still learning.

2 Answers2

2
function calc(val) {
  if (val < 1 || val > 10000) {
    alert("Value must be a positive number under 10,000")
    return 0;
  }
  if (val < 1001) return val*1.5;
  if (val < 5001) return val*1.2;
  return val;
}
mplungjan
  • 169,008
  • 28
  • 173
  • 236
0

This can be done trough almost every language available for web. Calculating is the most easy thing. For example, in PHP:

$output = $input - 5; // -5
$output = $input + 5; // +5
$output = $input++; // +1
$output = $input * 5; // x5

Javascript plus example:

var input = 5;
var plus = 6;
var output = input+plus;

Javascript min example:

var input = 5;
var plus = 6;
var output = input-plus;
Joran Den Houting
  • 3,149
  • 3
  • 21
  • 51
  • i dnt think so this gives an answer of the question .. i am not downvoting this but i am quiet confused bout your answer and upvote your answer got – Dhaval Nov 07 '13 at 09:33
  • @Dhaval He asked about calculating in javascipt or maybe other languages, so here are some examples. SO is ment to POINT someone in the right direction, NOT to give them a fully custom code they can use. Also he didn't gave any example of what he has tried to get any result, my answer was to show some basic calculating in PHP and Javascript so he could try to figure it out himself how to make the exact thing he need. – Joran Den Houting Nov 07 '13 at 09:36