際際滷

際際滷Share a Scribd company logo
Javascript Survival for Honesty and Humility Boolean Results AND  OR  NOT A B A&&B True True True True False False False True False False False False A B A||B True True True True False True False True True False False False A !(A) False True True False
The if statement if ( condition )  {  code to be executed if condition is true  } Example: <html><body> <script type=&quot;text/javascript&quot;> var d = new Date(); var time = d.getHours(); if (time < 10)  { document.write(&quot;<b>Good morning</b>&quot;); } </script> <p>This example demonstrates the If statement.</p> <p>If the time on your browser is less than 10, you will get a &quot;Good morning&quot; greeting.</p></body></html>
The if-else statement if ( condition )  {  code to be executed if condition is true  } else  {  code to be executed if condition is not true  } Example: <html><body><script type=&quot;text/javascript&quot;> var d = new Date(); var time = d.getHours(); if (time < 10)  { document.write(&quot;<b>Good morning</b>&quot;); } else { document.write(&quot;<b>Good day</b>&quot;); } </script> <p>This example demonstrates the If...Else statement.</p> <p>If the time on your browser is less than 10, you will get a &quot;Good morning&quot; greeting. Otherwise you will get a &quot;Good day&quot; greeting. </p></body></html>
The if-else if-else statement if ( condition1 )  {  code to be executed if condition1 is true  } else if ( condition2 )  {  code to be executed if condition2 is true  } else  {  code to be executed if condition1 and condition2 are not true  } Example: <script type=&quot;text/javascript&quot;> var d = new Date(); var time = d.getHours(); if (time<10)  {  document.write(&quot;<b>Good morning</b>&quot;);  } else if (time>10 && time<16)  {  document.write(&quot;<b>Good day</b>&quot;);  } else  {  document.write(&quot;<b>Hello World!</b>&quot;);  } </script>

More Related Content

Javascript survival2

  • 1. Javascript Survival for Honesty and Humility Boolean Results AND OR NOT A B A&&B True True True True False False False True False False False False A B A||B True True True True False True False True True False False False A !(A) False True True False
  • 2. The if statement if ( condition ) { code to be executed if condition is true } Example: <html><body> <script type=&quot;text/javascript&quot;> var d = new Date(); var time = d.getHours(); if (time < 10) { document.write(&quot;<b>Good morning</b>&quot;); } </script> <p>This example demonstrates the If statement.</p> <p>If the time on your browser is less than 10, you will get a &quot;Good morning&quot; greeting.</p></body></html>
  • 3. The if-else statement if ( condition ) { code to be executed if condition is true } else { code to be executed if condition is not true } Example: <html><body><script type=&quot;text/javascript&quot;> var d = new Date(); var time = d.getHours(); if (time < 10) { document.write(&quot;<b>Good morning</b>&quot;); } else { document.write(&quot;<b>Good day</b>&quot;); } </script> <p>This example demonstrates the If...Else statement.</p> <p>If the time on your browser is less than 10, you will get a &quot;Good morning&quot; greeting. Otherwise you will get a &quot;Good day&quot; greeting. </p></body></html>
  • 4. The if-else if-else statement if ( condition1 ) { code to be executed if condition1 is true } else if ( condition2 ) { code to be executed if condition2 is true } else { code to be executed if condition1 and condition2 are not true } Example: <script type=&quot;text/javascript&quot;> var d = new Date(); var time = d.getHours(); if (time<10) { document.write(&quot;<b>Good morning</b>&quot;); } else if (time>10 && time<16) { document.write(&quot;<b>Good day</b>&quot;); } else { document.write(&quot;<b>Hello World!</b>&quot;); } </script>