JavaScript conditional

Slides:



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

MONTEGO BAY HIGH SCHOOL INFORMATION TECHNOLOGY THE EXCEL IF FUNCTION.
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.
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.
COMP 14 Introduction to Programming Miguel A. Otaduy May 18, 2004.
Introduction to Computers and Programming Lecture 5 Boolean type; if statement Professor: Evan Korth New York University.
If Statements Sections 1.25, Control Structures o All code thus far executes every line of code sequentially o We want to be able to repeat,
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.
Programming with MATLAB. Relational Operators The arithmetic operators has precedence over relational operators.
Geography 465 Assignments, Conditionals, and Loops.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 30, 2005.
New Mexico Computer Science For All Booleans and Logic Maureen Psaila-Dombrowski.
Q and A for Section 4.4 CS 106, Fall Q1 Q: The syntax for an if statement (or conditional statement) is: if _______________ : _____________ A: if.
Programming Logic and Design Sixth Edition
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.
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.
CSC 107 – Programming For Science. Announcements.
PHY281Flow ControlSlide 1 Decisions In this section we will learn how to make decisions in a Java program  if Statements  if... else Statements  Comparison.
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.
Decision Structures and Boolean Variables. Sequence Structures Thus far, we’ve been programming “sequence structures” Thus far, we’ve been programming.
ICT Introduction to Programming Chapter 4 – Control Structures I.
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.
Python Basics  Values, Types, Variables, Expressions  Assignments  I/O  Control Structures.
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.
Introduction to Decision Structures and Boolean Variables
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.
Chapter 4: Making Decisions.
Variables A piece of memory set aside to store data
JavaScript, continued.
Chapter 4: Decision Structures and Boolean Logic
Introduction To Robot Decision Making
&& how we might use it in spreadsheets
JavaScript conditional
Computers & Programming Languages
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
Introduction to Decision Structures and Boolean Variables
Or how to put your search together by using connectors
Introduction To Robot Decision Making
Conditional Logic Presentation Name Course Name
Understanding Conditions
JavaScript conditional
Chapter 4: Boolean Expressions, Making Decisions, and Disk Input and Output Prof. Salim Arfaoui.
Pages:51-59 Section: Control1 : decisions
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"; }

When you have more than one decision to make nested else When you have more than one decision to make

Example If you live in the United States: US? Do you live in the District of Columbia or elsewhere? If you don’t live in the United States: Do you live in Europe or elsewhere? US? no yes DC? Europe? yes no no yes DC state Europe other

In JavaScript if (where == "US") { if (US == "DC") { report = "In DC"; } else { report = "In a state"; } } else if (continent == "Europe") { report = "In Europe"; } else report = "Other continent";

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)