# Calculator Ready codes

#### Tsippi

##### New Coder
Hello, I am building my site with wix and would like to add a special input calculator including basic functions like Multiplication, division, square root. Can i find ready codes for it ?

Hello, I am building my site with wix and would like to add a special input calculator including basic functions like Multiplication, division, square root. Can i find ready codes for it ?
Hi there,

Welcome to Code Forum! Code Forum is about learning, we can teach you how to get to make a calculator for you. But we won’t build it for you.

Would you like to learn how to build one?

Here's generally how those work... I'm not sure if you can use these on Wix, but here's how you can do it with PHP (backend server) and JavaScript (on the front end view / client side).

The PHP (server side) version of this works like such:
PHP:
``````\$sum = 5 + 3; // 8
\$multiply = 5 * 3; // 15
\$divide = 15/3; // 5
\$subtract = 3 - 1; // 2
\$squareroot =sqrt(4); // 2 -- square root of 4``````

We can do the same with JS:
JavaScript:
``````var sum = 5 + 3, // 8
multiply = 5 * 3, // 15
divide = 15/3, // 5
subtract = 3 - 1, // 2
squareroot = Math.sqrt(4); // 2 -- square root of 4``````

I wrote some functions for various bits of math and put them on Github, but I did them in PHP. You can convert them to JS like so:

php version example:
PHP:
``````function radiusCircum(\$radius){
// get the Circumference of a Circle, with the Radius supplied
return \$radius * 2 * pi();
}``````

new js version example:
JavaScript:
``````function radiusCircum(radius){
// get the Circumference of a Circle, with the Radius supplied
return radius * 2 * Math.PI;
}``````

Pros:
• Easy to use functions for math
• These functions can be easily converted to any language
Cons:
• There isn't a great reason to do this type of math in PHP

### php-math​

This is just a standalone functions page that makes it a bit easier to handle geometric validation and/or calculations on the server-side with PHP. I will admit, there are not many use cases for such functions.

### Circle Functions​

• radiusCircum(\$radius): returns the Circumference of a Circle, with the Radius supplied
• diamCircum(\$diam): get the Circumference of a Circle, with the diameter supplied
• radiusAreaCircle(\$radius): get the area of a circle, by supplying the radius
• diamAreaCircle(\$diam): get the area of a circle, by supplying the diameter

### Sphere Functions​

• radiusAreaSphere(\$radius): get the area of a sphere, by supplying the radius
• diamAreaSphere(\$diam): get the area of a sphere, by supplying the diameter
• areaTriangle(\$base, \$height): get the area of a triangle, by supplying the Base and Height lengths

### Distance functions​

• mile2kilo(\$miles): convert miles to kilometers
• kilo2mile(\$kilos): convert kilometers to miles
• twoObj_travelTime(\$speed_one, \$distance, \$speed_two)
• Measures the time it takes for two objects traveling a set distance, at two set speeds to meet each other (if they are on direct path towards each other)
• twoObj_travelDistance(\$speed_one, \$distance, \$speed_two, \$who = NULL)
• Measures the distance it takes for two objects traveling a set distance, at two set speeds to meet each other (if they are on direct path towards each other)
• The returned values will tell you how much distance Object 1 or 2 has covered in the time it took for them to meet each other in the middle
• Possible Return Values:
1. Array Keys: [1]=>Obj 1 Distance, and [2]=>Obj 2 Distance (this is the return if you do not specify Parameter 4 for Who)
2. If you specify 1, you get Obj 1 distance
3. If you specify 2, you get Obj 2 distance
View full php-math source on Github

Last edited: