LoginSignup
0
0

More than 3 years have passed since last update.

JavaScripの復習

Last updated at Posted at 2020-10-24

基本を見直しました。

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の指定範囲を変えましたが、エラーがでます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0