Donna M Ware
Donna M. Ware

Follow

Donna M. Ware

Follow

The Day There Wasn't Enough Sleep and Some Techie Explanations of Else/Else if Statements in JavaScript

Donna M Ware's photo
Donna M Ware
·Nov 30, 2022·

2 min read

The Day There Wasn't Enough Sleep and Some Techie Explanations of  Else/Else if Statements in JavaScript

Photo by Christopher Gower on Unsplash

Play this article

How many times have I started a post by saying, "What a day!," but What a fuckin' day...

I was running on low fuel to begin with, but I thought I could smash the day out and sleep tomorrow. My body had other plans and I didn't do much to fight it off. Now I am awake from my slumber, and feeling more tired than before my nap.

I did manage to get a webinar in, "How to Start an E-Commerce Business and Establish Your Online Presence." It was decent, I'll be writing a review on it, on my other blog platform Medium.

But, I'll link it here for those that are interested. I also read and did my favorite thing today, coding! And this is what I learned.

Else/Else if Statements in JavaScript

JavaScript makes your web pages interesting, in that, it makes your web pages functional and do cool things. This power, along with good content will make your website, app, or whatever project more likely to succeed. Else/Else if statements help you achieve this outcome.

So what are Else/Else if Statements and how do they work? let's get into it... When we are writing a program, we sometimes need it to make a decision(s) and go in a certain direction.

Kinda like when you're following directions. "Turn left at the gas station, but if you pass the gas station, turn right at the grocery store."

The key word in our example is "if" because Else/Else if statements work with conditional expressions to get their job done, like peanut butter and jelly.

if (condition)
  statement1

// With an else clause
if (condition)
  statement1
else
  statement2

the above code and all code examples are fromMDN, Mozillia.org

They give a complete explanation, just follow the above link if you need further explanation.

We use the "If Else" statement when we are working with more than one or multiple statements

if (x > 50) {
  /* do something */
} else if (x > 5) {
  /* do something */
} else {
  /* do something */
}

Well, I hope this brief explanation was enough to give some clarity. And I hope your day was a bit smoother than mine.

With these words, I bid you...

Good night

 
Share this