From the course: Coding for Visual Learners: Learning JavaScript from Scratch
Unlock this course with a free trial
Join today to access over 24,400 courses taught by industry experts.
Else Block - JavaScript Tutorial
From the course: Coding for Visual Learners: Learning JavaScript from Scratch
Else Block
- There is an additional structure that we can use with an if block. And that is called an else block. An else block follows an if block and is executed for every other comparison that is not covered by the if block. So we can create an else block here, which would mean that if the condition that is written here is now satisfied then execute whatever is inside the else block. So here we can put a text function but to differentiate between those two text function calls, we can call this one with the value of false. So now, if I'm to have a non-value of one this statement is going to get executed. But for every other value, this statement is going to get executed. So let's provide this non-variable, this value of 10. And then you'll see that the false is being displayed on the screen because the else statement is getting executed. By the way, notice how we are repeating ourselves by writing the text function twice. We…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.