JS+Conditionals (1)

JS+Conditionals (1) - } 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 [email protected]
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 (<Boolean expression 2>) { <then-statements 2>; } else if (<Boolean expression 3>) { <then-statements 3a>; <then-statement3b> } else if (<Boolean expression 4>) { <then-statements 4>; } else { < then-statements 5a>; // Default statements <then-statement5b>; } If a particular Boolean expression evaluates to true <then-statement> performed. Exit out of the if-else structure without checking for other matches. false <else-statement> skipped. Move to next Boolean expression check if it matches. Using Logical Operators with Conditionals • we can use the ‘&&’ (and) and ‘||’ (or) operators to join multiple expressions for the boolean test. • Remember: “a && b” means BOTH a and b have to be true “a || b” means EITHER one can be true...
View Full Document

This note was uploaded on 02/10/2011 for the course COMPUTER S 170 taught by Professor Stout during the Spring '10 term at Rutgers.

Page1 / 6

JS+Conditionals (1) - } else if (<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