2017-03-08 5 views
-1

このコードを実行すると、INVALID(100以上)とHigh Distinctionのみが動作します。 80より下の数字には、High Distinctionも表示されます。私は何を間違えたのですか?複数のelse if文を実行

function calculateGrade() { 
    var fvalue = Number(prompt('Please enter final score for unit. Enter a whole number only')); 

    document.write('The final score entered is ' + fvalue + '<br />'); 

    if (fvalue > 100) { 
     document.write('INVALID'); 
    } else if (80 <= fvalue <= 100) { 
     document.write('High Distinction'); 
    } else if (70 <= fvalue <= 79) { 
     document.write('Distinction'); 
    } else if (60 <= fvalue <= 69) { 
     document.write('Credit'); 
    } else if (50 <= fvalue <= 59) { 
     document.write('Pass'); 
    } else if (0 <= fvalue <= 49) { 
     document.write('Fail'); 
    } else if (fvalue < 0) { 
     document.write('INVALID'); 
    } 

} 

calculateGrade() 
+1

これは 'java'ではありません!それが詳細なコードの場合。タグを削除しない場合。 – nullpointer

答えて

0

比較構文が無効です。一度に1つの境界を確認する必要があります。

if (80 <= fvalue && fvalue <= 100) { 

他のものと同じです。ハイエンドがelseによって除外されているため

さらに一歩それを取るために、あなただけの、一方の境界をチェックする必要があります。

if (fvalue > 100) { 
    document.write('INVALID'); 
} else if (80 <= fvalue) { 
    document.write('High Distinction'); 
} else if (70 <= fvalue) { 
// ... 
0

これは、Javaではありません。 しかし、あなたは確かにこれを試すことができます。他

((fvalue> = 80)& &(fvalue < = 100)){ のdocument.write( 'ハイ区別')であれば、