+ 1

Trig Calculator Help

I want a user to be able to chose the function, and the units. I also want the code to run until it is given a viable answer. I cannot get it to work, and I do not really know what I am doing. I like variables, but functions are confusing, but I think I need to use them here. Here is the code: function X { var y = prompt("input "1" for sine, "2" for cosine, and "3" for tangent"); switch (y): case 1: var g = prompt(); var h = g*(Math.PI/180); var m = Math.sin(h); var n = m*(180/Math.PI); document.write(n); break; case 2: var i = prompt(); var j = i*(Math.PI/180); var o = Math.cos(j); var p = o*(180/Math.PI); document.write(p); break; case 3: var k = prompt(); var l = k*Math.PI/180; var q = Math.tan(l); var r = q*(180/Math.PI); document.write(r); break; default: alert("try again"); return(X) break; } function Y { var x = prompt("input "1" for sine, "2" for cosine, and "3" for tangent"); switch (x): case 1: var d = prompt("input radians, in fraction form. all input will be multiplied by PI/1"); document.write(Math.sin((d)*(Math.PI/1))); break; case 2: var e = prompt("input radians, in fraction form. all input will be multiplied by PI/1"); document.write(Math.cos((e)*(Math.PI/1))); break; case 3: var f = prompt("input radians, in fraction form. all input will be multiplied by PI/1"); document.write(Math.tan((f)*(Math.PI/1))); break; default: alert("try again"); return(Y) break; } do{ var a = prompt("input "0" for degrees, and "1" for radians"); if(a==0) { return(X) } else if(a==1) { return(Y) else{ alert("please input a "0" or a "1""); ; } } while(a=!0,1)

10th Nov 2017, 1:35 AM
Joshua Marmorstein
Joshua Marmorstein - avatar
4 odpowiedzi
+ 3
Please post your code in Code Playground and then link it here.
10th Nov 2017, 5:46 AM
Ekansh