I am making a simple cost estimator. It takes 3 imputed values X,Y,Z and displays a price which is a simple calculation of a value by the z axis (the third of 3 collected values).
You can view the estimator here: http://codepen.io/FredHair/pen/FgJAd
What I would like to add is a checkbox that when clicked would check that the smallest value is stored as the Z axis. So if the user imputed 3 values and the X or Y value was the smallest then that value would be swapped with with the z axis value.
How would I go about writing a function for this? Any help would be greatly appreciated even in pseudo code, which I could then write myself.
I have made a checkbox:
<input type="checkbox" id="zAxis">Z Axis Optimization<br>
This is my function for the Estimator:
//Calc with Switch//
function calculator(){
var x = Number(document.getElementById("x").value);
var y = Number(document.getElementById("y").value);
var z = Number(document.getElementById("z").value);
var p = Number(3);
var result;
var calc = document.getElementById("choice").value
switch(calc){
case"1" : result = z * p;
break;
case"2" : result = (z * p) + 50;
break;
case"3" : result = (z * p) + 30;
break;
}
//Display Result//
document.getElementById("result").innerHTML = " = £ " + result;
I know I will need to write a function like:
IF (x<=y && <=z) then do something
OR (y<=y && <=x) then do something
But any help will be greatly appreciated. Here is Codepen again: http://codepen.io/FredHair/pen/FgJAd
Thanks in advance.