jeudi 21 mai 2015

JavaScript if or statement not working

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 type in Sine it will work, but not if you type in Cosine or Tangent.

<script language="JavaScript">
var opposite = 1
var adjacent = 1
var hypotenuse = 1
var sct = "SohCahToa"
while (!(sct == ("Sine" || "Cosine" || "Tangent"))) {
    sct = prompt("Sine (unknown adjacent) / Cosine (unkown opposite side) / Tangent (unknown hypotenuse)")
    if (!(sct == ("Sine" || "Cosine" || "Tangent"))) {
        alert("Spelling error, please try again")
    }
}
if (sct == ("Sine" || "Cosine"))
    hypotenuse = prompt("What is the hypotenuse")
if (sct == ("Sine" || "Tangent"))
    opposite = prompt("What is the opposite side")
if (sct == ("Tangent" || "Cosine"))
    adjacent = prompt("What is the adjacent side")

Thanks (save the code as a .html to test it)

Aucun commentaire:

Enregistrer un commentaire