vendredi 27 février 2015

Javascript else if statement error

I have to make a javacript code that satisfy the triangle inequality theorem, which the two smaller sides adds up to be bigger than the largest side. I have to use javascript and use a prompt for users to enter three numbers. I can not ask the user to enter the largest number i have to find it by code. So below is what i got so far, but i keep getting an error at the first else if statement and so i wont run. Any idea whats wrong with my code?



<script type="text/javascript">
<!--


var a = prompt("Enter the first side", "0");
a = Number(a);
var b = prompt("Enter the second side", "0");
b = Number(b);
var c = prompt("Enter the third side", "0");
c = Number(c);

if(a>=b, a>=c){
if (b+c>a) {
document.write("These numbers " + a + ", " + b + ", and " + c + " do satisfy the triangle inequality.1" );
}
else {
document.write("These numbers " + a + ", " + b + ", and " + c + " do not satisfy the triangle inequality.1" );
}
else if(b>=c, b>=a) {
if (c+a>b) {
document.write("These numbers " + a + ", " + b + ", and " + c + " do satisfy the triangle inequality.2" );
}
else {
document.write("These numbers " + a + ", " + b + ", and " + c + " do not satisfy the triangle inequality.2" );
}
}
else {
if (a+b>c) {
document.write("These numbers " + a + ", " + b + ", and " + c + " do satisfy the triangle inequality.3" );
}
else {
document.write("These numbers " + a + ", " + b + ", and " + c + " do not satisfy the triangle inequality.3" );
}
}
}




// -->
</script>

Aucun commentaire:

Enregistrer un commentaire