If statement: Else clause

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

if (year == 2015) {
  alert( 'You guessed it right!' );
} else {
  alert( 'How can you be so wrong?' ); // any value except 2015
}

The if statement may contain an optional "else" block. It executes when the condition is wrong.

Related concepts

Else clause

If statement: Else clause — Structure map

Clickable & Draggable!

If statement: Else clause — Related pages: