XP Tutorial 2 New Perspectives on JavaScript, Comprehensive1 Working with Operators and Expressions Creating a New Year’s Day Countdown Clock.

Slides:



Advertisements
Similar presentations
Introducing JavaScript
Advertisements

Java Script Session1 INTRODUCTION.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
JavaScript Part for Repetition Statement for statement Cpecifies each of the items needed for counter-controlled repetition with a control variable.
1 HCI 201 JavaScript - Part 1. 2 Static web pages l Static pages: what we have worked with so far l HTML tags tell the browser what to do with the content.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
JavaScript Friend or Foe?. History of Java and JavaScript Oak and Coffee? ECMAscript European Computer Manufacturers Association JScript?
Tutorial 10 Programming with JavaScript
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
Tutorial 11 Working with Operators and Expressions
Tutorial 14 Working with Forms and Regular Expressions.
XP Tutorial 1 New Perspectives on JavaScript, Comprehensive1 Introducing JavaScript Hiding Addresses from Spammers.
Basic Elements of C++ Chapter 2.
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.
XP Tutorial 14 New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
Using Object-Oriented JavaScript CST 200- JavaScript 4 –
Tutorial 14 Working with Forms and Regular Expressions.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
Microsoft Visual Basic 2008: Reloaded Fourth Edition
Chapter 10 Creating Pop-Up Windows, Adding Scrolling Messages, and Validating Forms HTML5 & CSS 7 th Edition.
The Web Wizard’s Guide To JavaScript Chapter 6 Working with Dates and Times.
The Web Wizard’s Guide To JavaScript Chapter 6 Working with Dates and Times.
Creating an Animated Web Page
XP Tutorial 4 New Perspectives on JavaScript, Comprehensive1 Working with Objects Creating an Animated Web Page.
2440: 211 Interactive Web Programming Expressions & Operators.
Chapter 3: Data Types and Operators JavaScript - Introductory.
Copyright ©2005  Department of Computer & Information Science Using Number & Math Objects.
Chapter 12: How Long Can This Go On?
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
1 JavaScript in Context. Server-Side Programming.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
Tutorial 10 Programming with JavaScript. XP Objectives Learn the history of JavaScript Create a script element Understand basic JavaScript syntax Write.
Tutorial 10 Programming with JavaScript
Tutorial 8 Programming with ActionScript 3.0. XP Objectives Review the basics of ActionScript programming Compare ActionScript 2.0 and ActionScript 3.0.
Chapter 3 Assignment, Formatting, and Interactive Input C++ for Engineers and Scientists Third Edition.
Keeping it Neat: Functions and JavaScript Source Files Chapter 7.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
การสคริปท์ฝั่งลูกข่ายด้วย JavaScript การเขียนโปรแกรมเว็บ.
Chapter 3: Assignment, Formatting, and Interactive Input.
C++ for Engineers and Scientists Second Edition Chapter 3 Assignment, Formatting, and Interactive Input.
MCA-401: ADVANCE JAVA 1 DEPTT. OF COMP. SC & APPLICATIONS PREPARED BY : NAVEEN NAGPAL (SENIOR ASSISTANT PROFESSOR)
Client-Side Scripts JavaScript CIS January 2005.
XP Tutorial 8 Adding Interactivity with ActionScript.
XP New Perspectives on XML, 2 nd Edition Tutorial 7 1 TUTORIAL 7 CREATING A COMPUTATIONAL STYLESHEET.
1 JavaScript in Context. Server-Side Programming.
Chapter 3 Assignment, Formatting, and Interactive Input C++ for Engineers and Scientists Third Edition.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
XP Tutorial 7 New Perspectives on JavaScript, Comprehensive 1 Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
Tutorial 11 1 JavaScript Operators and Expressions.
XP Tutorial 3 New Perspectives on JavaScript, Comprehensive1 Working with Arrays, Loops, and Conditional Statements Creating a Monthly Calendar.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
JavaScript and Ajax (JavaScript Functions) Week 5 Web site:
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
JavaScript and AJAX 2nd Edition Tutorial 1 Programming with JavaScript.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
JavaScript Tutorial. What is JavaScript JavaScript is the programming language of HTML and the Web Programming makes computers do what you want them to.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
XP Tutorial 10 New Perspectives on JavaScript, Comprehensive 1 Working with Dynamic Content and Styles Creating a Dynamic Table of Contents.
2.3 Output Formatting. Outputting Format Specify the number of spaces, “c”, used to print an integer value with specifier %cd, e.g., %3d, %4d. E.g. printf.
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Chapter Topics The Basics of a C++ Program Data Types
Project 9 Creating Pop-up Windows, Adding Scrolling Messages, and Validating Forms.
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
SEEM4570 Tutorial 05: JavaScript as OOP
Arithmetic Operator Operation Example + addition x + y
Objectives Insert a script element Write JavaScript comments
T. Jumana Abu Shmais – AOU - Riyadh
The Web Wizard’s Guide To JavaScript
Presentation transcript:

XP Tutorial 2 New Perspectives on JavaScript, Comprehensive1 Working with Operators and Expressions Creating a New Year’s Day Countdown Clock

XP Tutorial 2New Perspectives on JavaScript, Comprehensive2 Objectives Work with event handlers Insert a value into a Web form field Create and work with date objects Extract information from date objects

XP Tutorial 2New Perspectives on JavaScript, Comprehensive3 Objectives Work with arithmetic, unary, conditional, and logical operators Understand the properties and methods of the Math object Understand how JavaScript works with numeric values Run time-delayed and timed-interval commands

XP Tutorial 2New Perspectives on JavaScript, Comprehensive4 Working with onEvent Processing Hector’s vision for Web site –Clock that updates itself every second Function to be created will –Calculate current date and time –Calculate time remaining until New Year’s Day –Run once every second

XP Tutorial 2New Perspectives on JavaScript, Comprehensive5 Form Field Names

XP Tutorial 2New Perspectives on JavaScript, Comprehensive6 Inserting the NYClock Function

XP Tutorial 2New Perspectives on JavaScript, Comprehensive7 Understanding Event Handlers Event –Action that occurs within a Web browser Event handler –Statement that tells browsers what code to run in response to specified event Syntax to insert event handler as an attribute...

XP Tutorial 2New Perspectives on JavaScript, Comprehensive8 JavaScript Event Handlers

XP Tutorial 2New Perspectives on JavaScript, Comprehensive9 Running JavaScript Commands as Links Syntax content The following code runs the calcTotal() function Calculate total cost

XP Tutorial 2New Perspectives on JavaScript, Comprehensive10 Working with Dates Date object –Contains information about a specified date and time –Syntax variable = new Date("month day, year hours:minutes:seconds");

XP Tutorial 2New Perspectives on JavaScript, Comprehensive11 Retrieve the Date, Month, and Hour Values Date methods –Used to retrieve information from or modify a date object Syntax to apply the getDate() method DateObject.getDate()

XP Tutorial 2New Perspectives on JavaScript, Comprehensive12 Retrieve the Date, Month, and Hour Values Storing value of current year in a variable ThisDate = new Date("February 24, :35:05"); thisYear = thisDate.getFullYear();

XP Tutorial 2New Perspectives on JavaScript, Comprehensive13 Retrieving the Hour, Minute, and Second Values Methods –DateObject.getSeconds() –DateObject.getMinutes( –DateObject.getHours()

XP Tutorial 2New Perspectives on JavaScript, Comprehensive14 Extracting Date and Time Values from Date Objects

XP Tutorial 2New Perspectives on JavaScript, Comprehensive15 Setting Date and Time Values for Date Objects

XP Tutorial 2New Perspectives on JavaScript, Comprehensive16 Creating a Date and Time Function showDate() function function showDate(dateObj) { thisDate = dateObj.getDate(); thisMonth = dateObj.getMonth()+1; thisYear = dateObj.getFullYear(); return thisMonth + "/" + thisDate + "/" + thisYear; }

XP Tutorial 2New Perspectives on JavaScript, Comprehensive17 Creating a Date and Time Function showTime() function function showTime(dateObj) { thisSecond=dateObj.getSeconds(); thisMinute=dateObj.getMinutes(); thisHour=dateObj.getHours(); return thisHour + ":" + thisMinute + ":" + thisSecond; }

XP Tutorial 2New Perspectives on JavaScript, Comprehensive18 Calling the showDate() and showTime() Functions

XP Tutorial 2New Perspectives on JavaScript, Comprehensive19 Working with Operators Operator symbol – Used to act upon an item or a variable within a JavaScript expression Arithmetic operators –Perform simple mathematical calculations

XP Tutorial 2New Perspectives on JavaScript, Comprehensive20 Arithmetic Operators

XP Tutorial 2New Perspectives on JavaScript, Comprehensive21 Arithmetic Operators Binary operators –Work with two items in an expression Unary operators –Work on only one item Increment operator –Used to increase the value of an expression by 1

XP Tutorial 2New Perspectives on JavaScript, Comprehensive22 Arithmetic Operators Decrement operator –Decreases an item’s value by 1 Negation operator –Changes the sign of (or negates) an item’s value

XP Tutorial 2New Perspectives on JavaScript, Comprehensive23 Unary Operators

XP Tutorial 2New Perspectives on JavaScript, Comprehensive24 Assignment Operators Used when assigning values to items within a JavaScript statement The following expressions create the same result x = x + y; x += y;

XP Tutorial 2New Perspectives on JavaScript, Comprehensive25 Assignment Operators

XP Tutorial 2New Perspectives on JavaScript, Comprehensive26 Calculating the Days Left in the Year Function needs to function calcDays(currentDate) { create a date object for January 1 of next year calculate the difference between currentDate and January 1 }

XP Tutorial 2New Perspectives on JavaScript, Comprehensive27 Adding Commands to the calcDays() Function

XP Tutorial 2New Perspectives on JavaScript, Comprehensive28 Calling the calcDays() Function

XP Tutorial 2New Perspectives on JavaScript, Comprehensive29 Working with Math Methods and Constants Math object –Used to perform mathematical tasks and store mathematical values Math methods –Used to perform advanced calculations Syntax for applying a Math method Math.method(expression)

XP Tutorial 2New Perspectives on JavaScript, Comprehensive30 Math Methods

XP Tutorial 2New Perspectives on JavaScript, Comprehensive31 Math Constants

XP Tutorial 2New Perspectives on JavaScript, Comprehensive32 Using the Math.floor() Method

XP Tutorial 2New Perspectives on JavaScript, Comprehensive33 Calculating the Hours, Minutes, and Seconds Left in the Year To calculate number of hours left in current day var hours = (days - Math.floor(days))*24; To calculate minutes left in current hour var minutes = (hours - Math.floor(hours))*60; To calculate seconds left in current minute var seconds = (minutes - Math.floor(minutes))*60;

XP Tutorial 2New Perspectives on JavaScript, Comprehensive34 Controlling How JavaScript Works with Numeric Values NaN –Not a Number isNaN() –Used to check whether a value is numeric –Syntax: isNaN(value)

XP Tutorial 2New Perspectives on JavaScript, Comprehensive35 Specifying the Number Format To control number of digits displayed by browser value.toFixed(n) Applying the toFixed() function testValue = 2.835; testValue.toFixed(0) // returns "3" testValue.toFixed(1) // returns "2.8" testValue.toFixed(2) // returns "2.84"

XP Tutorial 2New Perspectives on JavaScript, Comprehensive36 Numeric Functions and Methods

XP Tutorial 2New Perspectives on JavaScript, Comprehensive37 Working with Conditional Operators Conditional operator –Tests whether a certain condition is true or not –Syntax (condition) ? trueValue : falseValue Comparison operator –Compares value of one expression to another

XP Tutorial 2New Perspectives on JavaScript, Comprehensive38 Comparison Operators

XP Tutorial 2New Perspectives on JavaScript, Comprehensive39 Logical Operators

XP Tutorial 2New Perspectives on JavaScript, Comprehensive40 Running Timed Commands Time-delayed command –Run after a particular amount of time has passed –Syntax setTimeout("command", delay);

XP Tutorial 2New Perspectives on JavaScript, Comprehensive41 Running Commands at Specified Intervals Timed-interval command –Instructs browser to run same command repeatedly at specified intervals –Syntax setInterval("command",interval); –Method to stop command clearInterval();

XP Tutorial 2New Perspectives on JavaScript, Comprehensive42 Performing Special Mathematical Tasks Math.floor(), Math.ceil(), and Math.round() methods –Used to round values to the next highest, next lowest, and nearest integer No Math methods for –Rounding values to decimals

XP Tutorial 2New Perspectives on JavaScript, Comprehensive43 Generating Random Numbers Math.random() method –Generates random values Generating random number between 0 and 10 var randValue = 10*Math.random(); Generating random number from 20 to 30 var randValue = *Math.random();

XP Tutorial 2New Perspectives on JavaScript, Comprehensive44 Tips for Working with Operators and Expressions Use unary and assignment operators to create compact code When performing advanced mathematical calculations –Use constants from the Math object Never apply mathematical operations to text strings

XP Tutorial 2New Perspectives on JavaScript, Comprehensive45 Tips for Working with Operators and Expressions In case of logical error involving a mathematical operation –Use the isFinite() and isNaN() functions Use the toFixed() method to –Format numeric output