Logical Operators.  Quiz  Let's look at the schedule  Logical Operators 2.

Slides:



Advertisements
Similar presentations
Microsoft® Small Basic
Advertisements

Lecture 4 Basic Scripting. Administrative  Files on the website will be posted in pdf for compatibility  Website is now mirrored at:
Lets Play Catch! Keeping Score in Alice By Francine Wolfe Duke University Professor Susan Rodger May 2010.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
CIS101 Introduction to Computing Week 11. Agenda Your questions Copy and Paste Assignment Practice Test JavaScript: Functions and Selection Lesson 06,
Flow control 1: if-statements (Liang 72-80) if(radius < 0) { System.out.println(“cannot get area: radius below zero”); } else { double area = radius *
Macros Tutorial Week 20. Objectives By the end of this tutorial you should understand how to: Create macros Assign macros to events Associate macros with.
Main task -write me a program
JavaScript Events and Event Handlers 1 An event is an action that occurs within a Web browser or Web document. An event handler is a statement that tells.
Visual Basic Chapter 1 Mr. Wangler.
by Chris Brown under Prof. Susan Rodger Duke University June 2012
Xcode testing Using XCTest.
In.  This presentation will only make sense if you view it in presentation mode (hit F5). If you don’t do that there will be multiple slides that are.
Python Programming Using Variables and input. Objectives We’re learning to make use of if statements to enable code to ask questions. Outcomes Build an.
PROGRAMMING LANGUAGES Prof. Lani Cantonjos. PROGRAM - set of step-by-step instructions that tells or directs the computer what to do. PROGRAMMING LANGUAGE.
Nonvisual Arrays and Recursion by Chris Brown under Prof. Susan Rodger Duke University June 2012.
Engineering 1020 Introduction to Programming Peter King Winter 2010.
Instructors begin using McGraw-Hill’s Homework Manager by creating a unique class Web site in the system. The Class Homepage becomes the entry point for.
NMD202 Web Scripting Week3. What we will cover today Includes Exercises PHP Forms Exercises Server side validation Exercises.
BIT 115: Introduction To Programming Instructor: Mike Panitz
Conditional Execution
Conditions. Objectives  Understanding what altering the flow of control does on programs and being able to apply thee to design code  Look at why indentation.
® IBM Software Group © 2006 IBM Corporation JSF Progress Bar This Learning Module shows how to integrate EGL/JSF functionality into a run-time progress.
A Simple Quiz: Ask User Functions. By Lana Dyck under the direction of Professor Susan Rodger Duke University June 2009, added Part 2 July 2011.
JavaScript - Basic Concepts Prepared and Presented by Hienvinh Nguyen, Afshin Tiraie.
CPAA – Data entry - Time management. Grade Employee This WSR indicates the hours of work per week as well as the hours of work per day for this work schedule.
Application Day: Branching Adventure.  Quiz  Let's look at the schedule  Branching Adventure - explanation  Branching Adventure – work time 2.
Conditional Statements.  Quiz  Hand in your jQuery exercises from last lecture  They don't have to be 100% perfect to get full credit  They do have.
Loops.  (No Quiz)  Hand in Assignment #1  Last chance for Q+A on the midterm  Loops 2.
® Microsoft Access 2010 Tutorial 5 Creating Advanced Queries and Enhancing Table Design.
Event Handling. Objectives Using event handlers Simulating events Using event-related methods.
Radio Buttons.  Quiz  Radio Buttons  Check boxes 2.
CPSC 217 T03 Week V Part #1: Iteration Hubert (Sathaporn) Hu.
Functions.  Assignment #2 is now due on Wednesday, Nov 25 th  (No Quiz)  Go over the midterm  Backtrack and re-cover the question about tracing the.
CompSci 4 Chap 6 Sec 2 Sep 30, 2010 Prof. Susan Rodger “All your troubles are due to those ‘ifs’,” declared the Wizard. If you were not a Flutterbudget.
Controlling Program Flow with Decision Structures.
Let’s demonstrate some KRAD Action Components Kuali University: Apply Now Lab 3: Actions Lab Objectives Understand how to setup an action that invokes.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Lecture Exercise (Wk4) CS1301 Introduction To Computer Programming (11-12 Semester B) Page 1 Question 2 (a)Complete the code.
Check Boxes. 2 Check boxes  Image from:  HTML:  Each box gets it's own.
USING CONDITIONAL CODE AMIR KHANZADA. Conditional Statement  Conditional statements are the set of commands used to perform different actions based on.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
While loops. Iteration We’ve seen many places where repetition is necessary in a problem. We’ve been using the for loop for that purpose For loops are.
Microsoft® Small Basic Conditions and Loops Estimated time to complete this lesson: 2 hours.
CSE202: Lecture 5The Ohio State University1 Selection Structures.
CS320n –Visual Programming Execution Control with If / Else and Boolean Functions (Slides 6-2-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for.
Today… Python Keywords. Iteration (or “Loops”!) Winter 2016CISC101 - Prof. McLeod1.
Checking If User Input Is Numeric.  Quiz  Detecting numeric input  Finish Prior Lecture  Y'all work on one of the problems listed 2.
Conditionals.
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
Computer Science Up Down Controls, Decisions and Random Numbers.
IF STATEMENTS AND BOOLEAN EXPRESSIONS. BOOLEAN EXPRESSIONS Evaluate to a value of true or false Use relational or equivalence operators Boolean operators.
1 Week 8 Final Project Planning & Chapter 6 JavaScript Advanced Web Development IT225 Spring Term 2016 Marymount University School of Business Administration.
Logical Operators.  Quizzes!  Let's look at the schedule  Logical Operators 2.
BIT116: Scripting Lecture 05
Exsys Developer Tutorial
CMSC201 Computer Science I for Majors Lecture 03 – Operators
BIT116: Scripting Lecture 06
BIT 116:JavaScript.
BIT 116:JavaScript.
More Selections BIS1523 – Lecture 9.
Together Let’s Design an Online Quiz
Conditions and Ifs BIS1523 – Lecture 8.
CMSC201 Computer Science I for Majors Lecture 12 – Tuples
Programming in JavaScript
Introduction to TouchDevelop
Due Next Monday Assignment 1 Start early
Programming in JavaScript
Winter 2019 CISC101 4/16/2019 CISC101 Reminders
Presentation transcript:

Logical Operators

 Quiz  Let's look at the schedule  Logical Operators 2

 Assignment 1 ("A1") was posted last Friday  It's due on November 4 th (that's 1.5 weeks from today, and 1 week from next class)  You can (and should!!!) start work on it ASAP  We'll cover logical operators next class, which is the last piece you need to complete it.  The Midterm is on Monday, November 9 th, in class  The exam will be paper and pencil  You WILL be allowed to use your 3x5 card on the exam  I will be focusing on in-class exercises, material from the slides, and quizzes  MAKE SURE THAT ANYTHING YOU KNOW HOW TO DO ANYTHING THAT YOU MISSED ON ANY QUIZES!!!  I'll provide more detail later 3

4 Logical Operators: Concepts

5 The Logical Operators The three logical operators allow you to compare two conditional statements to see if one or both of the statements is true and to proceed accordingly. The logical operators can be useful if you want to check on more than one condition at a time and use the results. Like the comparison operators, the logical operators return either true or false, depending on the values on either side of the operator.

6 The AND Operator: && The logical && operator returns true if the comparisons on both sides of the && operator are true. If one or both comparisons on either side of the operator are false, a value of false is returned.

7 The OR Operator: || The logical || operator returns true if the comparison on either side of the operator returns true. So, for this to return true, only one of the statements on one side needs to evaluate to true. To return false, the comparisons on both sides of the operator must return false.

8 The NOT Operator: ! The logical ! operator can be used on a single comparison to say, “If this is not the case, then return true.” Basically, it can make an expression that would normally return false return true, or make an expression that would normally return true return false.

 Do something if….  ALL the criteria are met (if all the conditions are true) AND &&  ANY ONE (or more) the criteria are met OR (if any of the conditions are true) ||  You want to reverse the true/false value of something NOT !  Use parentheses to indicate the first thing you want to evaluate, the second thing, etc 9

 Be prepared to report out about this. 10

11 Logical Operators: Basic JavaScript

12

Feedback to the user:  30  that's the secret number!  Between 20 and 40  it's close, but not right  Outside the range  it's out of range  Input isn't a number  Tell the user that 13

"use strict"; $(document).ready( function() { $("#logicalOps").click( function() { var guess = $("#input").val(); guess = parseInt(guess); if( isNaN( guess ) ) { $("#output").html("You must type a number!"); return; } You've seen the above before – when the document is ready to run JS, install an event handler for when the button with the id of 'logicalOps' is clicked. Get whatever the user typed in, convert it to a whole number, and if it's not a number then tell the user that and stop. 14

if (guess 100) { $("#output").html("Your guess is out of bounds!"); return; }  The way to check for out of bounds is: If the number is below the bottom of the range OR above the top of the range  guess < 1 = below the bottom of the range  || = OR  guess > 100 = above the top of the range  If so then display an error message and stop the function 15

else if (guess > 20 && guess < 40 /* && guess != 30 */) { $("#output").html("You're getting closer!"); return; }  The way to check for a number being within bounds is: If the number is above the bottom of the range AND below the top of the range  guess > 20 = above the bottom of the range  && = AND  guess < 40 = below the top of the range  If so then display an error message and stop the function  Note: the comment demonstrates that you can add more criteria if you want  /* && guess != 30 */ 16

 When evaluating a logical expression AND ( && ) is evaluated before OR ( || )  Example: You're done when you've chosen option A and then finished either Task #1 or Task #2. Code: var choseOptionA = false; // Task #1/#2 don't matter since we var finishedTask1 = false; // didn't choose option 1 var finishedTask2 = true; //  WRONG:  if( choseOptionA && finishedTask1 || finishedTask2)  Why?  choseOptionA && finishedTask1 || finishedTask2   false && false || true // AND GOES FIRST   false || true   true 17

 When evaluating a logical expression AND ( && ) is evaluated before OR ( || )  Use parentheses to force a different order  RIGHT:  if( choseOptionA && ( finishedTask1 || finishedTask2 ) )  Why?  choseOptionA && ( finishedTask1 || finishedTask2 )   false && ( false || true ) // substitute, parens then force || to go first   false && true   false 18

 Work on Exercises #2 and #3 for this part of this lecture 19