From 8308ffa6288db7d07155e91ce75d037ecdb3483d Mon Sep 17 00:00:00 2001 From: John Redden Date: Sun, 22 Nov 2020 22:26:32 -0500 Subject: [PATCH 1/2] completed functions --- js/formulas.js | 73 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 52 insertions(+), 21 deletions(-) diff --git a/js/formulas.js b/js/formulas.js index 2435d53..454064f 100644 --- a/js/formulas.js +++ b/js/formulas.js @@ -1,80 +1,111 @@ -// Basic math formulaas +//Values + +// let num1 = Number(prompt("Enter a number:")); +// let num2 = Number(prompt("Enter a second number:")); +//let side = Number(prompt("How long is a side of the square?")); +// let length = Number(prompt("What is the length?")); +// let width = Number(prompt("What is the width?")); +// let base = Number(prompt("What is the length of the base?")); +// let height = Number(prompt("What is the height?")); +//let radius = Number(prompt("What is the radius?")); +// let side1 = Number(prompt("How long is the first side?")); +// let side2 = Number(prompt("How long is the second side?")); +// let side3 = Number(prompt("How long is the third side?")); +//let diameter = Number(prompt("What is the diameter?")); + +let num1 = 4; +let num2 = 5; +let side = 6; +let length = 8; +let width = 12; +let base = 9; +let height = 5; +let radius = 10; +let π = Math.PI; +let side1 = 2; +let side2 = 7; +let side3 = 3; +let diameter = 15; + +// Basic math formulas + function addition(num1, num2){ - return -1; + return num1 + num2; } function subtraction(num1, num2){ - return -1; + return num1 - num2; } function multiplication(num1, num2){ - return -1; + return num1 * num2; } function division(num1, num2){ - return -1; + return num1 / num2; } -// Area formulaas +// Area formulas + function areaSquare(side){ - return -1; + return Math.pow(side, 2); } function areaRectangle(length, width){ - return -1; + return length * width; } function areaParallelogram(base, height){ - return -1; + return base * height; } function areaTriangle(base, height){ - return -1; + return (1/2) * base * height; } function Circle(radius){ - return -1; + return π * Math.pow(radius, 2); } function Sphere(radius){ - return -1; + return 4 * π * Math.pow(radius, 2); } // Surface Area formulas function surfaceAreaCube(side){ - return -1; + return 6 * Math.pow(side, 2); } function surfaceAreaCylinder(radius, height){ - return -1; + return 2 * π * radius * height; } // Perimeter formulas function perimeterSquare(side){ - return -1; + return 4 * side; } function perimeterRectangle(length, height){ - return -1; + return (2 * length) + (2 * height); } function perimeterTriangle(side1, side2, side3){ - return -1; + return side1 + side2 + side3; } function perimeterCircle(diameter){ - return -1; + return π * diameter; } // Volume formulas function volumeCube(side){ - return -1; + return Math.pow(side, 3); } function volumeRectangular(length, width, height){ - return -1; + return length * width * height; } function volumeCylinder(radius, height){ - return -1; + return π * Math.pow(radius, 2) * height; } From 26deb98f901929622db6a5862515d9f67d18c3a1 Mon Sep 17 00:00:00 2001 From: John Redden Date: Tue, 24 Nov 2020 20:45:57 -0500 Subject: [PATCH 2/2] removed redundant value definitions and simplified use of pi --- js/formulas.js | 38 +++++--------------------------------- 1 file changed, 5 insertions(+), 33 deletions(-) diff --git a/js/formulas.js b/js/formulas.js index 454064f..0ca095d 100644 --- a/js/formulas.js +++ b/js/formulas.js @@ -1,31 +1,3 @@ -//Values - -// let num1 = Number(prompt("Enter a number:")); -// let num2 = Number(prompt("Enter a second number:")); -//let side = Number(prompt("How long is a side of the square?")); -// let length = Number(prompt("What is the length?")); -// let width = Number(prompt("What is the width?")); -// let base = Number(prompt("What is the length of the base?")); -// let height = Number(prompt("What is the height?")); -//let radius = Number(prompt("What is the radius?")); -// let side1 = Number(prompt("How long is the first side?")); -// let side2 = Number(prompt("How long is the second side?")); -// let side3 = Number(prompt("How long is the third side?")); -//let diameter = Number(prompt("What is the diameter?")); - -let num1 = 4; -let num2 = 5; -let side = 6; -let length = 8; -let width = 12; -let base = 9; -let height = 5; -let radius = 10; -let π = Math.PI; -let side1 = 2; -let side2 = 7; -let side3 = 3; -let diameter = 15; // Basic math formulas @@ -64,11 +36,11 @@ function areaTriangle(base, height){ } function Circle(radius){ - return π * Math.pow(radius, 2); + return Math.PI * Math.pow(radius, 2); } function Sphere(radius){ - return 4 * π * Math.pow(radius, 2); + return 4 * Math.PI * Math.pow(radius, 2); } // Surface Area formulas @@ -77,7 +49,7 @@ function surfaceAreaCube(side){ } function surfaceAreaCylinder(radius, height){ - return 2 * π * radius * height; + return 2 * Math.PI * radius * height; } // Perimeter formulas @@ -94,7 +66,7 @@ function perimeterTriangle(side1, side2, side3){ } function perimeterCircle(diameter){ - return π * diameter; + return Math.PI * diameter; } // Volume formulas @@ -107,5 +79,5 @@ function volumeRectangular(length, width, height){ } function volumeCylinder(radius, height){ - return π * Math.pow(radius, 2) * height; + return Math.PI * Math.pow(radius, 2) * height; }