! sign means left and right sides are not equal to each other. Basically, IS NOT that is what the ! mark means...
Logical And, Or,
If (A == B) {
If (A != B) {
If (A === B) {
If (A !=== B) {
If (A > B) {
If (A < B) {
If (A >=B) {
If (A<= B) {
If ( a !=== b) && (c === d) both sides must be true
If ( a !=== b) || (c === d) either side must be true
If (( a>b) && (c<d)) both sides must be true
Let's write a little program....
I got tired of writing scripts that are somewhat mundane... So lets write a program that that let's a visitor know when he/she can come in...
As as a programmer you have to think ahead... If you paste this code and run it, type 25 and up... See the problem?
This is where the nesting loops are handy..
What is that?
It is a nest within a nest.
Basically, think of this way.
The day is only 24 hours, correct?
The office is closed before 9 am and closes at 5 pm.
1st thing - we need to block anything above 24. If a person types 25, you will see a message "We are not on Jupiter!"
Define var officeHours;
var officeHours = prompt("What time would you like to drop by?");
Your first If/Else statement is
if (officeHours < 24) { ;} else { document.write("We are not on Jupiter!"); }
Since the statement is true hours are less than 24... right below 1st { we need to add
if (officeHours>=9 && officeHours<=17) { document.write("we are open!"); }
We are telling the script that the office is opened between 9 and 17... && is logical operator that tell us that both statement left and right must be TRUE!
If the prompt result falls under 9 or over 18, the office is closed.
else { document.write("closed!"); }
After this else... you are done with a nested If Else loop...
TADA!
<script> var officeHours = prompt("What time would you like to drop by?");
if (officeHours < 24) { if (officeHours >=9 && officeHours <=17) { document.write("We are open"); } else { document.write("We are closed!"); } } else { document.write("We are not on Jupiter!"); } </script>
<script> var officeHours = prompt("What time would you like to drop by?"); var weekoftheDay = prompt("Would you like to come on Saturday or Sunday?"); var weekoftheDay = false;
<script> var officeHours = prompt("What time would you like to drop by?");