HTML calculator (probably dead simple)

Soldato
Joined
3 Jun 2005
Posts
7,588
I’m after a simple calculator with 3 fields for height, width and length, and a dropdown for CM or MM. I need it to calculate how many whole 20cm cubes will fit into the space given.

I imagine this is one line of code.

Thanks.
 
Soldato
Joined
6 Mar 2008
Posts
10,079
Location
Stoke area
Do you want this in HTML/jscript or would any language do?

Probably more complex than you think.

off the top of my head, i'd take 3 variables, divide each by 20cm to make sure you only get whole boxes the multiple them together.

think that would work ok. but then you've got to take in conversions of mm to cm etc
 
Last edited:
Soldato
Joined
6 Mar 2008
Posts
10,079
Location
Stoke area
I don't know javascript but python something simple like this would work if it was only in cm:

height = int(input("Enter the height: ")
width = int(input("Enter the width: ")
length = int(input("Enter the length: ")

print(int((height/20))*int((width/20))*int((length/20)))
 
Associate
Joined
24 Jun 2008
Posts
1,168
Code:
    function doit(){
        document.getElementById("out").value = (document.getElementById("X").value/20)*(document.getElementById("Y").value/20)*(document.getElementById("Z").value/20);
    }

Not checking the mm/cm thing, no validation or anything and you have to create the inputs by yourself!
 
Back
Top Bottom