JavaScript學習筆記(十一) ─ if條件語句

Yanwei Liu
2 min readMay 23, 2019

--

if

let year = prompt('In which year was ECMAScript-2015 specification published?', '');

if (year == 2015) alert( 'You are right!' );
if (year == 2015) {
alert( "That's correct!" );
alert( "You're so smart!" );
}

“if”+”else”

if (year == 2015) {
alert( 'You guessed it right!' );
} else {
alert( 'How can you be so wrong?' ); // 2015 以外的任何值
}

else if

let year = prompt('In which year was ECMAScript-2015 specification published?', '');

if (year < 2015) {
alert( 'Too early...' );
} else if (year > 2015) {
alert( 'Too late' );
} else {
alert( 'Exactly!' );
}
let company = prompt('Which company created JavaScript?', '');

if (company == 'Netscape') {
alert('Right!');
} else {
alert('Wrong.');
}

--

--

No responses yet