JAVSCRIPT基礎のif

1568 ワード

if:もし、else:その他
if...else...判定式が必要です.条件を満たす時だけ実行します.
else文は前の条件が全部満たされない時に実行できます.
ifの簡単な使い方 
var score = 116;
//  if-else    
if(score >90){
console.log('    ')
}
else{
console.log('     ')
}
 if…elseの簡単な使い方
var score = 133;
//  if-else    
if(score > 130){
console.log('    ')
}
else if(130 >= score > 120){
console.log('    ')
}
else if(120 >= score > 90){
console.log('    ')
}
else {
console.log('     ')
}
 並ぶif elseの使い方
var all_scores = {'  ':[131,143,144],
    '  ':[131,135,144],
    '   ':[127,139,142],
    '   ':[123,148,136],
    '   ':[126,135,140],
    '   ':[129,133,138],
    '  ':[116,143,140],
    '   ':[114,142,139],
    '   ':[115,139,135],
    '   ':[116,142,129]};
var highest_score ;
var stu_name = '   ';
//     if  if-else         
if(all_scores[stu_name][0]>all_scores[stu_name[1]])
{
    highest_score = all_scores[stu_name][0]
}
else
{
     highest_score = all_scores[stu_name][1];
}
if(highest_score < all_scores[stu_name][2])
{
    highest_score = all_scores[stu_name][2]
}
console.log('          :'+highest_score);