基本を見直しました。
if文をswich文に、書き直して見ました。
if文のコード
var firstName ="yourname";
var age = 18;
if(age < 15){
console.log(firstName + 'is a junior high school student');
} else if(age >=15 && age < 18 {
console.log(firstName + 'is a high school student');
} else if(age >=18 && age < 20) {
console.log(firstName + 'is a university student');
} else {
console.log(firstName + 'is a salary man');
}
}
これをswich文に書き直すと
swich文
var firstName = "yourname";
age = 24;
switch (true){
case age < 13:
console.log(firstName + 'is a junior high school student.');
break;
case age >=13 && age < 18:
console.log(firstName + 'is a high school student.');
break;
case age >=18 && age < 22:
console.log(firstName + 'is a university student.');
break;
default:
console.log(firstName +'is a salaryman.');
}
出たエラーメッセージ
Uncaught SyntaxError: Unexpected end of input
自分で試したこと
ageの指定範囲を変えましたが、エラーがでます。