coop coop - 2 months ago 9
Javascript Question

Need help creating a javascript function that calculates based on increments

I need assistance creating a javascript function that performs the below logic.

If cubic ft is between 2500-5000 invoice $42, but if greater than 5000 then invoice $42 plus $22 per 1000 cubic ft.

Here is what I have so far:

var assessfee = function(cubicft) {
if (cubicft > 2500 || cubicft <= 5000) {
console.log($42);
} else if (cubicft > 5000) {
var diff = cubicft - 5000;

}
}

Answer

Something like this? Basically that sets the price to 42 since that is the default price and if cubicft is > 5000 it takes that divided by 1000 then takes it times 22 and adds that value to price. Finally it prints it to the console.

var assessfee = function(cubicft) { 
    var price = 42;
    if (cubicft > 5000) {
        price += (cubicft-5000)/1000*22;
    }
    console.log("$" + price);
}