JavaScript conditional

Slides:



Advertisements
Similar presentations
Selection Victor Norman CS104 Calvin College. Reading Quiz Counts toward your grade.
Advertisements

CS&E 1111 ExIFs IFs and Nested IFs in Excel Objectives: Using the If function in spreadsheets Nesting If functions.
Chapter 4 Control Structures I. Objectives ► Examine relational and logical operators ► Explore how to form and evaluate logical (Boolean) expressions.
Decisions (Conditional Programming) Chapter 5 (Sec. 5.1 & 5.2)
1 9/24/07CS150 Introduction to Computer Science 1 Relational Operators and the If Statement.
Introduction to Computers and Programming Lecture 5 New York University.
Boolean Expressions Conditional Statements & Expressions CSC 1401: Introduction to Programming with Java Lecture 4 – Part 2 Wanda M. Kunkle.
Introduction to Computers and Programming Lecture 5 Boolean type; if statement Professor: Evan Korth New York University.
Comparing Numeric Values If Val(Text1.Text) = MaxPrice Then (Is the current numeric value stored in the Text property of Text1 equal to the value stored.
1 Lecture 7:Control Structures I (Selection) Introduction to Computer Science Spring 2006.
1 CS150 Introduction to Computer Science 1 Relational Operators and the If Statement 9/22/08.
CS 1400 Jan 2007 Chapter 4, sections Relational operators Less than< Greater than> Less than or equal= Equal== Not equal!=
Programming with MATLAB. Relational Operators The arithmetic operators has precedence over relational operators.
Geography 465 Assignments, Conditionals, and Loops.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design First Edition by Tony Gaddis.
Chapter 8 Conditionals. Learning Java through Alice © Daly and Wrigley Objectives List relational operators. List logical operators. Use the hierarchy.
PAGES:51-59 SECTION: CONTROL1 : DECISIONS Decisions.
1. We’ve learned that our programs are read by the compiler in order, from top to bottom, just as they are written The order of statement execution is.
Computer Science 210 Computer Organization Introduction to Boolean Algebra.
MS3304: Week 6 Conditional statements. Overview The flow of control through a script Boolean Logic Conditional & logical operators Basic decision making.
CHAPTER 4: Selection Control Structure. Objectives  Use the relational comparison operators  Learn about AND logic  Learn about OR logic  Make selections.
If…else statements. Boolean Expressions Boolean expression - An expression whose value is either true or false true = 1 false = 0 Datatype: boolean.
1 2. Program Construction in Java. 2.4 Selection (decisions)
Programming 1 DCT 1033 Control Structures I (Selection) if selection statement If..else double selection statement Switch multiple selection statement.
Conditions, Logical Expressions, and Selection Control Structures ROBERT REAVES.
Section 3.4 Boolean Algebra. A link between:  Section 1.3: Logic Systems  Section 3.3: Set Systems Application:  Section 3.5: Logic Circuits in Computer.
CONDITIONALS. Boolean values Boolean value is either true or false It is name after the British mathemetician, George Boole who first formulated Boolean.
Logical Operators, Boolean Variables, Random Numbers This template was just too good to let go in one day!
Laws of Boolean Algebra Commutative Law Associative Law Distributive Law Identity Law De Morgan's Theorem.
Chapter 6 Conditionals. Learning Java through Alice © Daly and Wrigley Objectives List relational operators. List logical operators. Use the hierarchy.
Pascal Programming George Boole, a 19 th Century mathematician, is created with true, false logic. A Boolean expression in Pascal will be true or false.
Design A software design specifies how a program will accomplish its requirements A design includes one or more algorithms to accomplish its goal.
Chapter 7 Conditional Statements. 7.1 Conditional Expressions Condition – any expression that evaluates to true/false value Relational operators are BINARY.
 Type Called bool  Bool has only two possible values: True and False.
Computer Science 210 Computer Organization
JavaScript, continued.
Selection (also known as Branching) Jumail Bin Taliba by
Brent M. Dingle Texas A&M University Chapter 6, Sections 1 and 2
Chapter 6 Conditionals.
Section 7.1 Logical Operators
Chapter 4: Making Decisions.
JavaScript Objects.
Variables A piece of memory set aside to store data
JavaScript, continued.
Chapter 4: Decision Structures and Boolean Logic
JavaScript conditional
Introduction To Robot Decision Making
&& how we might use it in spreadsheets
JavaScript conditional
Bools and simple if statements
Computer Science 210 Computer Organization
Chapter 4: Decision Structures and Boolean Logic
Chapter 7 Conditional Statements
Pages:51-59 Section: Control1 : decisions
Logical Operations In Matlab.
Three Special Structures – Case, Do While, and Do Until
Introduction to Decision Structures and Boolean Variables
Introduction To Robot Decision Making
Conditional Logic Presentation Name Course Name
Understanding Conditions
Chapter 4: Boolean Expressions, Making Decisions, and Disk Input and Output Prof. Salim Arfaoui.
The Selection Structure
Pages:51-59 Section: Control1 : decisions
Computer Programming Boolean Logic Trade & Industrial Education
Millennium High School Agenda Calendar
Chapter 4: Decision Structures and Boolean Logic
Lecture 9: JavaScript Syntax
3.0 - Design A software design specifies how a program will accomplish its requirements A design includes one or more algorithms to accomplish its goal.
Conditionals.
Chapter 6 Conditionals.
Presentation transcript:

JavaScript conditional

Boolean Logic Basis for modern computer logic George Boole Basis for modern computer logic Works with only two values George Boole was an english mathematician and philosopher. Born 1815, died 1864.

BOOLEAN VARIABLE OR EXPRESSION Holds either true or false can pass as a literal Can be thought of as yes or no Open excel – type true or false into a cell, and show that excel automatically capitlizes & centers it. TRUE & FALSE are special values in excel.

Is greater than or equal to Boolean expressions Creates a Boolean value from numbers or strings Operator Meaning == Is equal to != Is not equal > Is greater than < Is less than >= Is greater than or equal to <= Is less than or equal to

Conditionals Test if a Boolean expression is true or false Allows a program to make a choice

IF … THEN … ELSE if (MUST BE LOWERCASE) no else: do nothing if not true else: one or the other else if: series of choices

More complicated IF example Let’s assign letter grades to students! 90 - 100 – A 80 - 89 – B 70 - 79 – C 60 - 69 – D <60 – F Nested If: =IF(H2>=90, “A”, If(H2 >=80, “B”, “C or Below”)) Longer Nested if: =IF(H2>=90, "A", IF(H2>=80, "B", IF(H2>=70, "C", IF(H2 >=60, "D", "Fail"))))

Decision Tree grade < 60 F grade < 70 D grade < 80 C B A

In JavaScript if (num < 60) { grade = "F"; } else if (num < 70) { grade = "D"; } else if (num < 80) { grade = "C"; } else if (num < 90) { grade = "B"; } else { grade = "A"; }

In JavaScript JavaScript statement(s) if (num < 60) { grade = "F"; } else if (num < 70) { grade = "D"; } else if (num < 80) { grade = "C"; } else if (num < 90) { grade = "B"; } else { grade = "A"; } JavaScript statement(s)

Combining Boolean expressions

Operations on Booleans AND OR Are all of them true? && Is it a big dog? (size==“big” && pet==“dog”) Number between 5 and 10 (num>=5 && num<=10) Are any of them true? || Is it either blue or black? (color==“blue” || color==“black”) Number less than 10 or greater than 20 (num<10 || num>20)