Reputation: 5
I have been trying to create an expression to calculate brick and glass prices.
I'm working with a, b and c
so the price is $30m^2 for bricks and $20m^2 for glass
A and B are walls C is a round window radius
A = 3m (not m^2)
B = 2m (not m^2)
C = 1m (not m^2)
I believe that my expression (a*b)*30 – (c^2*20) works but how can I turn this into a java script function that in future I could use in a calculator to calculate prices etc...
Bit of a newbie with java script.
thanks all!
Upvotes: 0
Views: 129
Reputation: 8345
I believe the following function cost(a,b,c)
should do what you want, assuming I've understood the question:
function cost(a,b,c) {
return (a * b * 30) - (Math.PI * Math.pow(c,2) * 20)
}
This returns 117.16814692820414
given the parameters a = 3
, b = 2
and a = 1
.
An example of the cost
function in use would be:
var price = cost(3,2,1);
Upvotes: 1