JavaScript Part 2.

Slides:



Advertisements
Similar presentations
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 4 Making Decisions in a Program.
Advertisements

 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Programming with MATLAB. Relational Operators The arithmetic operators has precedence over relational operators.
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.
CH Programming An introduction to programming concepts.
JavaScript – Part II Data Types and Operations George Mason University June 3, 2010.
 Input and Output Functions Input and Output Functions  OperatorsOperators Arithmetic Operators Assignment Operators Relational Operators Logical Operators.
2440: 211 Interactive Web Programming Expressions & Operators.
Chapter 3: Data Types and Operators JavaScript - Introductory.
JavaScript, jQuery, and Mashups Incorporating JavaScript, jQuery, and other Mashups into existing pages.
Operators Precedence - Operators with the highest precedence will be executed first. Page 54 of the book and Appendix B list C's operator precedence. Parenthesis.
PHY-102 SAPVariables and OperatorsSlide 1 Variables and Operators In this section we will learn how about variables in Java and basic operations one can.
Assignment statement: Assigns a value to a variable Variable must appear on the left side, value on the right side of the assignment operator Right side.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Fluency with Information Technology Third Edition by Lawrence Snyder Chapter.
Part:2.  Keywords are words with special meaning in JavaScript  Keyword var ◦ Used to declare the names of variables ◦ A variable is a location in the.
CECS 5020 Computers in Education Visual Basic Variables and Constants.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Introduction to Calculated Columns Variables, Conditionals, and String Manipulation PRESENTER: Cameron Blashka| Informer Implementation Specialist| April.
CHAPTER 10 JAVA SCRIPT.
Topics Designing a Program Input, Processing, and Output
Chapter 6 JavaScript: Introduction to Scripting
Web Development & Design Foundations with HTML5
CHAPTER 5 SERVER SIDE SCRIPTING
University of Central Florida COP 3330 Object Oriented Programming
Operators Operators are symbols such as + (addition), - (subtraction), and * (multiplication). Operators do something with values. $foo = 25; $foo – 15;
Programming Fundamental
2.5 Another Java Application: Adding Integers
Overview: Programming Concepts
University of Central Florida COP 3330 Object Oriented Programming
Assignment statement:
Variables, Expressions, and IO
Introduction to Scripting
More C++ Basics October 4, 2017.
Javascript Conditionals.
3rd prep. – 2nd Term MOE Book Questions.
Selection By Ramin && Taimoor
Operators and Expressions
Statements, Comments & Simple Arithmetic
Conditional Statements
Exercises on JavaScript & Revision
Introduction to C++ Programming
MSIS 655 Advanced Business Applications Programming
T. Jumana Abu Shmais – AOU - Riyadh
CS105 Introduction to Computer Concepts
Reading Input from the Keyboard
2.1 Solving Linear Inequalities
SELECTIONS STATEMENTS
2.1 – 2.2 Solving Linear Inequalities
JavaScript.
Chapter 3: Selection Structures: Making Decisions
Boolean Expressions to Make Comparisons
Web Development & Design Foundations with H T M L 5
Topics Designing a Program Input, Processing, and Output
Relational Operators.
Topics Designing a Program Input, Processing, and Output
Chapter 3: Selection Structures: Making Decisions
JavaScript: Introduction to Scripting
Web Programming– UFCFB Lecture 13
The Selection Structure
Using C++ Arithmetic Operators and Control Structures
Agenda Warmup Review Finish 1.2 Assignments Lesson 1.3 (If Statements)
Web Programming and Design
CS105 Introduction to Computer Concepts JavaScript
Intro to Programming (in JavaScript)
Agenda Warmup Review Finish 1.2 Assignments Lesson 1.3 (If Statements)
COMPUTING.
Web Development & Design Foundations with HTML5 7th Edition
Presentation transcript:

JavaScript Part 2

Arithmetic Operators When working with variables it is always useful to do some calculations. Operators are the symbols used to work with variables. Operator Description Example Value of Quantity = assign quantity = 10 10 + addition quantity = 10 + 6 16 - subtraction quantity = 10 - 6 4 * multiplication quantity = 10 * 2 20 / division quantity = 10 / 2 5

Arithmetic Operators Operator What it does x % y Modulus of x and y (remainder of the division) -x Reverse the sign on x x + y (Numeric) Adds x and y together x + y (String) Concatenates text x and text y together “black” + “cat” produces “blackcat”

Assignments When you put a value into a variable, you are assigning that value to the variable, and you use an assignment operator to do the job. X=Y Sets X to the value of Y X+=Y Same as X = X + Y X-=Y Same as X = X – Y X*=Y Same as X = X * Y X/=Y Same as X = X / Y X%=Y Same as X = X % Y

Arithmetic Operators Result = Result + 1; Shorthand: Result +=1;

Sample values of quantity that would result in true Comparison Operators Operator Description Example Sample values of quantity that would result in true = = Double equals sign (equivalent) “is exactly equal to” quantity = = 10 10 > Greater than quantity > 10 11, 12 (but not 10) > = Greater than or equal to quantity > = 10 10, 11, 12 < Less than quantity < 10 8, 9 (but not 10) < = Less than or equal to quantity < = 10 8, 9, 10 ! = Not equal to quantity ! = 10 8, 9, 11 (but not 10)

Logical Operators ! (not) && (and) || (or)

Decision Making if (condition) { … commands to execute if condition is true } else { … commands to execute if condition is false

Decision making: example if(Day==“Friday”){ document.write(“Have a nice weekend!”); } else{ document.write(“Good Morning!”);

Decision making: example2 If(Day==“Friday” || Day==“Saturday”) { document.write(“Have a nice weekend!”); } else { document.write(“Good Morning!”);

Nested if then .. else statements var country = “france”; if (country==“spain”) { document.write(“buenos dias”); } else { if (country==“italy”) {document.write(“buon giorno”);} {if (country==“france”) {document.write(“bonjour”);}

Hands-on practice 2 The user will be prompted for a quantity and must enter a quantity greater than 0. If the user enters a value that is 0 or a negative number, an error message should be displayed. If the user has inserted a positive value, write “thank you” to the screen. Use prompt method & write the message to the document.

The code:

JS resources http://www.w3schools.com/js/ http://www.Lynda.com http://www.youtube.com/watch?v=_cLvpJY2deo