JS%2BConditionals

JS%2BConditionals - } else if (<Boolean...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 170: JS If statements Prof. Jim Appenzeller speaker@rci.rutgers.edu
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Syntax: confirm ("a question you need to ask the  user"); the Confirm Function
Background image of page 2
Conditional Statements the  'if'  statement Syntax: if(<Boolean expression>) { <then-statement1>; <then-statement2>; <then-statement3>; } <Boolean expression> an expression with an outcome of either true or false. <then-statement>  (one or zero) or more JavaScript statements. depends on how we use brackets Always use the curly braces,  { and }  for your if- statements.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
If-Else Statements Allows execution of a set of statements if a  condition is true and another set of statements if  condition is false if (<Boolean expression>) { <then-statement1>; <then-statement2>; <then-statement3>; } else { <else-statement>; }
Background image of page 4
“if – else if – else” Basic Structure: if (<Boolean expression 1>) { <then-statements 1>;
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } else if (&amp;lt;Boolean expression 2&amp;gt;) { &amp;lt;then-statements 2&amp;gt;; } else if (&amp;lt;Boolean expression 3&amp;gt;) { &amp;lt;then-statements 3a&amp;gt;; &amp;lt;then-statements3b&amp;gt; } else if (&amp;lt;Boolean expression 4&amp;gt;) { &amp;lt;then-statements 4&amp;gt;; } else { &amp;lt; then-statements 5a&amp;gt;; // Default statements &amp;lt;then-statements5b&amp;gt;; } If a particular Boolean expression evaluates to true &amp;lt;then-statement&amp;gt; performed. Exit out of the if-else structure without checking for other matches. false &amp;lt;else-statement&amp;gt; skipped. Move to next Boolean expression check if it matches. Using Logical Operators with Conditionals we can use the &amp;amp;&amp;amp; (and) and || (or) operators to join multiple expressions for the boolean test. Remember: a &amp;amp;&amp;amp; b means BOTH a and b have to be true a || b means EITHER one can be true...
View Full Document

Page1 / 6

JS%2BConditionals - } else if (&amp;amp;amp;lt;Boolean...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online