From 62742aa1f94074265c3f5cd0da0036b123672c33 Mon Sep 17 00:00:00 2001 From: michael-mcmasters Date: Wed, 18 Nov 2020 21:22:16 -0500 Subject: [PATCH] Make all functions return a result --- js/formulas.js | 79 +++++++++++++++++++++++++------------------------- 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/js/formulas.js b/js/formulas.js index 2435d53..ae755f6 100644 --- a/js/formulas.js +++ b/js/formulas.js @@ -1,80 +1,81 @@ -// Basic math formulaas -function addition(num1, num2){ - return -1; +// Basic math formulas +function addition(num1, num2) { + return num1 + num2; } -function subtraction(num1, num2){ - return -1; +function subtraction(num1, num2) { + return num1 + num2; } -function multiplication(num1, num2){ - return -1; +function multiplication(num1, num2) { + return num1 * num2; } -function division(num1, num2){ - return -1; +function division(num1, num2) { + return num1 / num2; } // Area formulaas -function areaSquare(side){ - return -1; +function areaSquare(side) { + return Math.pow(side, 2); } -function areaRectangle(length, width){ - return -1; +function areaRectangle(length, width) { + return length * width; } -function areaParallelogram(base, height){ - return -1; +function areaParallelogram(base, height) { + return base * height; } -function areaTriangle(base, height){ - return -1; +function areaTriangle(base, height) { + return 0.5 * base * height; } -function Circle(radius){ - return -1; +function Circle(radius) { + return Math.PI * Math.pow(radius, 2); } -function Sphere(radius){ - return -1; +function Sphere(radius) { + return 4 * Math.PI * Math.pow(radius, 2); } // Surface Area formulas -function surfaceAreaCube(side){ - return -1; +function surfaceAreaCube(side) { + return 6 * Math.pow(side, 2); } -function surfaceAreaCylinder(radius, height){ - return -1; +function surfaceAreaCylinder(radius, height) { + return 2 * Math.PI * radius * height; } // Perimeter formulas -function perimeterSquare(side){ - return -1; +function perimeterSquare(side) { + return 4 * side; } -function perimeterRectangle(length, height){ - return -1; +// Note! Changed length param to width because that is what the foruma showed +function perimeterRectangle(length, width) { + return 2 * length + 2 * width; } -function perimeterTriangle(side1, side2, side3){ - return -1; +function perimeterTriangle(side1, side2, side3) { + return side1 + side2 + side3; } -function perimeterCircle(diameter){ - return -1; +function perimeterCircle(diameter) { + return Math.PI * diameter; } // Volume formulas -function volumeCube(side){ - return -1; +function volumeCube(side) { + return Math.pow(side, 3); } -function volumeRectangular(length, width, height){ - return -1; +function volumeRectangular(length, width, height) { + return length * width * height; } -function volumeCylinder(radius, height){ - return -1; +function volumeCylinder(radius, height) { + return Math.PI * Math.pow(radius, 2) * height; }