I am making a simple trigonometry program in javascript and my if and while statements are not working properly, as they only pass if the first condition is true i.e. if you
I would use an array for the options, and a case statement below:
var opposite = 1
var adjacent = 1
var hypotenuse = 1
var sct = "SohCahToa"
var options = ["Sine", "Cosine", "Tangent"];
while (options.indexOf(sct) < 0) {
sct = prompt("Sine (unknown adjacent) / Cosine (unkown opposite side) / Tangent (unknown hypotenuse)");
sct = options[options.indexOf(sct)];
if (options.indexOf(sct) < 0) {
alert("Spelling error, please try again");
}
}
switch (sct) {
case "Sine":
hypotenuse = prompt("What is the hypotenuse")
opposite = prompt("What is the opposite side")
break;
case "Cosine":
hypotenuse = prompt("What is the hypotenuse")
adjacent = prompt("What is the adjacent side")
break;
default:
opposite = prompt("What is the opposite side")
adjacent = prompt("What is the adjacent side")
}