Calculator Code
Calculator Code
javascript: var versionCalc = prompt('1). Basic Calculator\n2). Equations');switch (versionCalc) {Â case '1':Â Â var operatorType = parseInt(prompt('1). Addition\n2). Subtraction\n3). Multiplication\n4). Division'));Â Â switch (operatorType) {Â Â Â case 1:Â Â Â Â var num1 = parseInt(prompt('First Number:'));Â Â Â Â var num2 = parseInt(prompt('Second Number:'));Â Â Â Â result = num1 + num2;Â Â Â Â break; Â Â Â case 2:Â Â Â Â var num1 = parseInt(prompt('First Number:'));Â Â Â Â var num2 = parseInt(prompt('Second Number:'));Â Â Â Â result = num1 - num2;Â Â Â Â break; Â Â Â case 3:Â Â Â Â var num1 = parseInt(prompt('First Number:'));Â Â Â Â var num2 = parseInt(prompt('Second Number:'));Â Â Â Â result = num1 * num2;Â Â Â Â break; Â Â Â case 4:Â Â Â Â var num1 = parseInt(prompt('First Number:'));Â Â Â Â var num2 = parseInt(prompt('Second Number:'));Â Â Â Â result = num1 / num2;Â Â Â Â break; Â Â Â default:Â Â Â Â alert('That is not a valid input. Input the number of the operation you are trying to run');Â Â Â Â break;Â Â };Â break;Â case '2':Â Â var equationType = parseInt(prompt('1). Slope\n2). Area of a circle\n3). Area of a square/rectangle\n4). Area of a triangle\n5). Volume of a cube\n6). Distance\n7). Time\n8). Speed'));Â Â switch (equationType) {Â Â Â case 1:Â Â Â Â m = parseInt(prompt("What is the rise/run? (M)"));Â Â Â Â x = parseInt(prompt("What is the distance of the line from the x-axis? (X)"));Â Â Â Â b = parseInt(prompt("What is the Y-Intercept? (B)"));Â Â Â Â result = (m * x) + b;Â Â Â Â break;Â Â Â case 2:Â Â Â Â r = parseInt(prompt(%27What is the radius of the circle? (R)%27));Â Â Â Â r2 = r * r;Â Â Â Â result = r2 * 3.14;Â Â Â Â break;Â Â Â case 3:Â Â Â Â l = parseInt(prompt(%27What is the length?%27));Â Â Â Â w = parseInt(prompt(%27What is the width?%27));Â Â Â Â result = l * w;Â Â Â Â break;Â Â Â case 4:Â Â Â Â b = parseInt(prompt("What is the base of the triangle?"));Â Â Â Â h = parseInt(prompt("what is the height of the triangle?"));Â Â Â Â result = (b * h) / 2;Â Â Â Â break;Â Â Â case 5:Â Â Â Â l = parseInt(prompt(%27What is the length?%27));Â Â Â Â w = parseInt(prompt(%27What is the width?%27));Â Â Â Â h = parseInt(prompt(%27What is the height?%27));Â Â Â Â result = l * w * h;Â Â Â Â break; Â Â Â case 6:Â Â Â Â s = parseInt(prompt(%27What is the speed?%27));Â Â Â Â t = parseInt(prompt(%27What is the time?%27));Â Â Â Â result = s * t;Â Â Â Â break;Â Â Â case 7:Â Â Â Â s = parseInt(prompt(%27What is the speed?%27));Â Â Â Â d = parseInt(prompt(%27What is the distance?%27));Â Â Â Â result = d / s;Â Â Â Â break;Â Â Â case 8:Â Â Â Â s = parseInt(prompt(%27What is the time?%27));Â Â Â Â d = parseInt(prompt(%27What is the distance?%27));Â Â Â Â result = d / t;Â Â Â Â break;Â Â Â Â Â Â default:Â Â Â Â alert(%27That is not a valid input. Input the number of the operation you are trying to run%27);Â Â Â Â break;Â Â };Â break;Â default:Â Â alert(%27That is not a valid input. Input the number of the operation you are trying to run%27);Â };alert(%27Your answer is %27 + result);