Hey everybody I want to let you know that I have undertaken the grueling task of getting the heck away from WordPress. I was so sick of the problems and updates I had to do all the time. I am now using my ezbloo system and I am integrating all my old posts into the new system. It sucks, but in the end, I will save bundles of time. I needed to keep things simple and that is why I created ezbloo. I'll have more on this later for you guys after I am done with the total integration of my old posts here. So if you are looking for a post and need it faster, shoot me an email and I will make it a priority. [email protected]

Sometimes you want to check if we meet 2 or more conditions in JavaScript. To accomplish this we use the OR "||", AND "&&" statements within the IF condition. In the last lesson  we were checking the date. If a certain date met the condition we displayed something. What if we had a couple of dates where we wanted to display something? Lets see how this can accomplish this in JavaScript.

new Date().getDay

We can get the number of the day with a JavaScript function.  Notice that the first number in this function starts with "0". So Sunday would be equal to "0" and Saturday would be equal to "6". If you use the code below, it will display today's day.
<script>
var x = document.getElementById('foo');
var y = new Date().getDay();
x.innerHTML=y;&lt;/script&gt;</pre>
<h2>Using OR || in The Condition Statement</h2>
Now what we want to do is display "It's The Weekend" on Friday, Saturday and Sunday. On the rest of the days we will display, "Have a nice day". Lets see how this is accomplished.
<pre class="EnlighterJSRAW" data-enlighter-language="generic">&lt;script&gt;
var x = document.getElementById('foo');
var y = new Date().getDay();
if(y==5 || y==6 || y==0){
x.innerHTML="Its The Weekend!";
}else{
x.innerHTML="Have A Nice Day";
}
</script>

Explanation of Code

This will give us the number of the current day. We store that in a variable called "y". Next we started our if statement and conditions. We are checking to see if the day is Friday, Saturday, or Sunday. If it is, then we display, "It's The Weekend". We then use the "else" statement for every other day to display, "Have a Nice Day". Now let's go over using "AND &&" in the conditions statement on the next page.

Using "AND  &&" in The Conditions Statement

Sometimes we need to check and see if 2 condition are met. Let's say we wanted to display "Its the Weekend In June" in June. Then for rest of the months we just want to say "It's the Weekend". How can we accomplish this? Look at this code.
<script>
var x = document.getElementById('foo');
var y = new Date().getDay();
var z = new Date().getMonth();

if(y==5 || y==6 || y==0 && z==5){
x.innerHTML="Its The Weekend in June!";
}else if(y==5 || y==6 || y==0){
x.innerHTML="Its the weekend";
}else{
x.innerHTML="Have a Nice Day";
}
</script>

Explanation of Code

We made a few changes from the previous code. The first change is we set a new variable of "z". With it we got the month of the year. Remember that the numbering starts at "0". In JavaScript, you have 0 to 11 for the months, so the month of June would be #5. In the IF condition, we added "&& z==5" to check and see if we were in June. If we met the conditions we display, "It's the weekend in June". Next, we added a "else if" statement to check for another condition. We are checking to make sure the days are still the weekend, however NOT the weekend in June. If we meet this condition, then we display "Have a Nice Day. The next page will have video instructions. Click here to go to next page. 

Video Instructions


Next Lesson