top of page

Or has a credit card and I could say equal is true here but I'll just skip it for the sake of brevity has a credit card and we have not reached the credit limit. Right. And you're going to put this on the same line above and then we execute our code block. So and you know maybe internet marketing services India put this on the same line so it's a bit easier to read. So you have to scroll over a bit but you know for the purpose of this demo I think it will make sense to have it all in one line. Right.

 

So let me scroll this over a little bit. Right, so we're checking basically a couple of things here. We're checking if this returns true. We don't even bother to check the other side. We know that right. If this returns true it's just that we go ahead and execute the code block. But we have an OR statement here. So if this happens to return false if it evaluates to false it's going to move on and it's going to do this check and then if this check if these expression returns are true then it's going to go ahead and execute the code in the code block the code inside the block anyway. All right.

 

So let's see if we got it right. Console log. Contracts. You can make this purchase a smiley face. All right so we'll move our console back over here and we'll clear it will run. Looks like internet marketing services India can make the purchase right. So we have a credit card. We haven't reached our credit limit. That's OK with me. Now if we can go around you know we change this to true what happens. Well, we can't make the purchase at that point because of one of our conditions here. In fact, both of them evaluate to false.

 

So this is false and this is now false. If we reset this get rid of the not operator then it will run. And this is a big part of you know getting your statements to work is if you're having trouble you probably want to evaluate your logic at some point. Maybe you think you're returning true or you think you're returning false on something and you may just need a night operator somewhere where your logic is kind of misplaced.

To complete our understanding of internet marketing services India we need to understand else as well and it's kind of in the name as to what it does kind of gives a hint right. So if the if statement runs it just runs Otherwise we can give it some other code to run it fails to execute. So if we were to rewrite our statement here let's simplify our lives a little bit let's just do one check here. So we'll check the bank account and the cost of the item. Get rid of the rest of this code there. Right.

 

So we'll say if you have enough cash we'll say congratulates you can pay for this with cash. For example. OK. So we know that this first condition will fail to run. We know we don't have enough cash if we do our cash right our bank balance goes up payday. Hey, we can now pay with cash. OK. That's cool. But right now where we're not really doing anything if we don't have enough cash right. So we don't even know. Nothing happens no code executes it just gets to this point. This value is false. And then it doesn't do anything.

 

So we want to do an else clause as well. So we check if it fails to run. We can do else and you know different developers have different style a lot of people put else on the same line as this. You may occasionally also see internet marketing services India on its own line. So just really a stylistic difference. I am kind of partial to putting it directly after the closing block line here but it doesn't really make a difference. It doesn't make a difference at all actually in either case.

 

So here we can say if you have enough money great. Otherwise, it's a log. Sorry, you cannot purchase this item sad face. There you go. All right. So this way if this block of code fails to execute we're always just going to run this. Otherwise, this is going to end here. Right. So it's in the name right. Do this or else do something else. So let's try it out. Sorry, you cannot purchase this item. What if we did happen to have enough cash. You would expect not to see this block to run and you'd be correct. Right. So let's try that out the boom. You can pay with cash or else statement was not triggered.

 

Makes sense right. So as you can see internet marketing services India is pretty intuitive once you kind of grasp the concept of an if statement and then you can have these things Ness's as well. So this can go pretty deep if you need it to say you can say if blah blah blah. Right, right now we're going to fail to purchase it. And then inside of our else, we can say it has a credit card and has reached a credit limit. So we have not noticed not OUR have not reached the credit limit console log. Congrats. You can pay for this with credit. Right. And then we can do an else statement in here as well.

 

Console log. So we can't afford and then we can get rid of this line down here so you can see it can get pretty complicated if you need it to be. But here I can clear. Run it again. Hey, congrats. I can pay for it with a credit card. So this failed. We ran our IF statement and then this ran. And you know we could nest all the way down if we need to be honest however many levels. But at that point, it starts to get a little bit too tedious to work. But this is an if else there's also something called else. If so you can have an if statement with an if else if a whole bunch of ifs. And then finally an else to close it off so to show you what I mean by that.

bottom of page