From c72e8627cab52e0f38c64d9c23cbfbecb9aeb8d0 Mon Sep 17 00:00:00 2001 From: StephanieCzetli Date: Tue, 22 Dec 2020 11:48:15 -0500 Subject: [PATCH] completed JS Formulas --- js/formulas.js | 113 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 88 insertions(+), 25 deletions(-) diff --git a/js/formulas.js b/js/formulas.js index 2435d53..cfd103f 100644 --- a/js/formulas.js +++ b/js/formulas.js @@ -1,80 +1,143 @@ -// Basic math formulaas -function addition(num1, num2){ - return -1; +// Basic math formulas +function addition(num1, num2) { + let sum = num1 + num2 + return sum; } +//addition (-2,1) +//-1 function subtraction(num1, num2){ - return -1; + let difference = num1 - num2 + return difference; } +// subtraction(4,5) +// -1 -function multiplication(num1, num2){ - return -1; + +function multiplication(num1, num2) { + let answer = num1 * num2 + return answer; } +// multiplication (3,4) +// 12 + -function division(num1, num2){ - return -1; +function division(num1, num2) { + let answer = num1/ num2 + return answer; } +// division (12,4) +// 3 -// Area formulaas +// Area formulas function areaSquare(side){ - return -1; + let answer = side * side + return answer; } +// areaSquare (10) +// 100 -function areaRectangle(length, width){ - return -1; +function areaRectangle(length, width) { + let answer = length * width + return answer; } +// areaRectangle(4, 5) +// 20 + function areaParallelogram(base, height){ - return -1; + let answer = base * height + return answer; } +// areaParallelogram(8,6) +// 48 function areaTriangle(base, height){ - return -1; + let answer = (1/2) * base * height + return answer; } +// areaTriangle (3, 4) +// 6 function Circle(radius){ - return -1; + let answer = (radius * radius) * Math.PI + return answer; } +// Circle(4); +// 50.26548245743669 + function Sphere(radius){ - return -1; +let answer = (radius * radius) * 4 * Math.PI + return answer; } +// Sphere(5); +// 314.1592653589793 // Surface Area formulas function surfaceAreaCube(side){ - return -1; + let answer = 6 * (side * side) + return answer; } +// surfaceAreaCube(7); +// 294 function surfaceAreaCylinder(radius, height){ - return -1; + let answer = 2 * Math.PI * radius * height + return answer; } +// surfaceAreaCylinder(3,7); +// 131.94689145077132 // Perimeter formulas function perimeterSquare(side){ - return -1; + let answer = 4*side + return answer; } +// perimeterSquare (16); +// 64 function perimeterRectangle(length, height){ - return -1; + let answer = 2*length + 2*height + return answer; } +//perimeterRectangle(2,3) +//10 + function perimeterTriangle(side1, side2, side3){ - return -1; + let answer = side1 + side2 + side3 + return answer; } +// perimeterTriangle(2,3,4) +// 9 + function perimeterCircle(diameter){ - return -1; + let answer = Math.PI*diameter + return answer; } +// perimeterCircle(12) +// 37.69911184307752 // Volume formulas function volumeCube(side){ - return -1; + let answer = side * side * side + return answer; } +// volumeCube(2) +// 8 function volumeRectangular(length, width, height){ - return -1; + let answer = length*width*height + return answer; } +// volumeRectangular(4,5,6) +// 120 function volumeCylinder(radius, height){ - return -1; + let answer = Math.PI * (radius * radius) * height + return answer; } +// volumeCylinder(6,7) +//791.6813487046279