JS Conditionals - } else if (<Boolean expression...

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 part 1 Kristian Stout stouty@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
the Confirm Function Syntax: confirm ("a question you need to ask the  user");
Background image of page 2
Conditional Statements the  'if'  statement Syntax: if(<Boolean expression>) { <then-statement>; <then-statement2>; <then-statment2>; } <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-statement>; <then-statement2>; <then-statment2>; } 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 (&lt;Boolean expression 2&gt;) { &lt;then-statements 2&gt;; } else if (&lt;Boolean expression 3&gt;) { &lt;then-statements 3a&gt;; &lt;then-statement3b&gt; } else if (&lt;Boolean expression 4&gt;) { &lt;then-statements 4&gt;; } else { &lt; then-statements 5a&gt;; // Default statements &lt;then-statement5b&gt;; } If a particular Boolean expression evaluates to true &lt;then-statement&gt; performed. Exit out of the if-else structure without checking for other matches. false &lt;else-statement&gt; skipped. Move to next Boolean expression check if it matches. Using Logical Operators with Conditionals we can use the &amp;&amp; (and) and || (or) operators to join multiple expressions for the boolean test. Remember: a &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 Conditionals - } else if (&amp;amp;lt;Boolean expression...

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