JavaScript Assignment Statements Expressions Global Functions CST 200 JavaScript.

Slides:



Advertisements
Similar presentations
1 COMM 1213 H1 COMP 4923 X1 JavaScript 1 (Readings: Ch. 10, 11 Knuckles)
Advertisements

Operators and Expressions Operators are symbols that produce a result based on some rules. Examples: +, -, =, > and
JavaScript Objects - DOM CST 200 JavaScript. Objectives Introduce JavaScript objects Introduce Document Object Model Introduce window object Introduce.
1 CSC 551: Web Programming Spring 2004 client-side programming with JavaScript  scripts vs. programs  JavaScript vs. JScript vs. VBScript  common tasks.
Types and Arithmetic Operators
1 Programmer-Defined Functions Functions allow program modularization Variables declared in function are local variables Only known inside function in.
Lesson 4: Formatting Input Data for Arithmetic
JavaScript- Processing HTML Forms. Event Handlers Begins with and ends with.
Javascript Essentials How do I write it??  Start Homesite  Between the start and end BODY tags type: 
CIS101 Introduction to Computing Week 10 Spring 2004.
CIS101 Introduction to Computing Week 10. Agenda Your questions Final exam and final project CIS101 Student Survey Class presentations: Your Mad Libs.
Javascript II Expressions and Data Types. 2 JavaScript Review programs executed by the web browser programs embedded in a web page using the script element.
1  Ex: Declare a variable to store user’s age: int age; Prompt the user to enter his/her age: printf (“ How old are you? “); Read / scan the entered value.
1 CS101 Introduction to Computing Lecture 29 Functions & Variable Scope (Web Development Lecture 10)
Identifiers and Assignment Statements. Data structures In any programming language you need to refer to data The simplest way is with the actual data.
INLS 560 – V ARIABLES, E XPRESSIONS, AND S TATEMENTS Instructor: Jason Carter.
CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT
JavaScript – Part II Data Types and Operations George Mason University June 3, 2010.
1 VBA – podstawowe reguły języka Opracowanie Janusz Górczyński wg Microsoft Help.
CMPS 211 JavaScript Topic 1 JavaScript Syntax. 2Outline Goals and Objectives Goals and Objectives Chapter Headlines Chapter Headlines Introduction Introduction.
CHAPTER 4 Java Script อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
Topic: An Introduction to JavaScript - from Beginning JavaScript by Wilton (WROX)
Computer Science 101 Introduction to Programming.
Ch 6: JavaScript Introduction to scripting part 2.
Principles of programming languages 5: An operational semantics of a small subset of C Department of Information Science and Engineering Isao Sasano.
The Grammar of JavaScript.  Each line of a script is a statement  An instruction that JavaScript can evaluate (make sense of)  Ends with a semicolon;
Keeping it Neat: Functions and JavaScript Source Files Chapter 7.
Web Programming Language Week 5 Dr. Ken Cosh Introducing PHP 1.
JavaScript Syntax and Semantics. Slide 2 Lecture Overview Core JavaScript Syntax (I will not review every nuance of the language)
Introducing JavaScript. Goals By the end of this lecture you should … Be able to describe the differences among object methods, object properties and.
CS346 Javascript -3 Module 3 JavaScript Variables.
Basic Data Types Numbers (integer and floating point)‏ Strings (sequences of characters)‏ Boolean values (true/false)‏
Neal Stublen What's a class?  A class is comprised of a set of data and the actions taken on that data  Each action is represented.
Input & Output Functions JavaScript is special from other languages because it can accept input and produce output on the basis of that input in the same.
JavaScript Syntax, how to use it in a HTML document
Introduction to Programming JScript Six Scripting functions Discuss functions Password Example.
Variables and Data Types Data (information we're going to store) – Numbers – Text – Dates What types of data can JavaScript process? How do we store it?
JavaScript, Fourth Edition
1 Functions, Part 1 of 2 Topics Using Predefined Functions Programmer-Defined Functions Using Input Parameters Function Header Comments.
CSCE 102 – Chapter 11 (Performing Calculations) CSCE General Applications Programming Benito Mendoza Benito Mendoza 1 By Benito Mendoza.
CHAPTER 6 Introduction to PHP5 Part I อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
JavaScript 1 COE 201- Computer Proficiency. Introduction JavaScript scripting language ▫Originally created by Netscape ▫Facilitates disciplined approach.
Programming Paradigms By Tyler Smith. Event Driven Event driven paradigm means that the program executes code in reaction to events. The limitation of.
Java Script About Java Script Document Object Model Incorporating JavaScript Adding JavaScript to HTML Embedding a Javascript External Scripts Javascript.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Variables.
1 Variables and Arithmetic Operators in JavaScript.
Expressions and Data Types Professor Robin Burke.
Modern JavaScript Develop And Design Instructor’s Notes Chapter 4 – Simple Variable Types Modern JavaScript Design And Develop Copyright © 2012 by Larry.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are created using a declaration statement. For example: Dim.
JavaScript Variables. Definition A variable is a "container" for information you want to store. A variable's value can change during the script.
Arithmetic Instructions. Integer and Float Conversions.
 2001 Prentice Hall, Inc. All rights reserved. Outline 1 JavaScript.
Data Type and Function Prepared for CSB210 Pemrograman Berorientasi Objek By Indriani Noor Hapsari, ST, MT Source: study.
Chapter 6 JavaScript: Introduction to Scripting
© 2016, Mike Murach & Associates, Inc.
Programming the Web using XHTML and JavaScript
Variables and Arithmetic Operators in JavaScript
Exploring JavaScript Ch 14
JavaScript Syntax and Semantics
JavaScript and Ajax (Expression and Operators)
JavaScript an introduction.
PHP.
JavaScript What is JavaScript? What can JavaScript do?
Variables Kevin Harville.
We are starting JavaScript. Here are a set of examples
An Introduction to JavaScript
JavaScript What is JavaScript? What can JavaScript do?
Introducing JavaScript
JavaScript: Introduction to Scripting
Murach's JavaScript and jQuery (3rd Ed.)
Presentation transcript:

JavaScript Assignment Statements Expressions Global Functions CST 200 JavaScript

Objectives Introduce JavaScript Assignment Statements and Expressions Introduce Global Properties and Functions

Assignment Statements In previous examples, we have used assignment statements to assign values to variables var user = "Joe Smith"; Declare variable named user Assign the string value Joe Smith to the variable user

Assignment Statements (cont) Assignment statements are used to assign (set) a value to a variable Assignment statements use the assignment operator ( = ) The right-side of the assignment statement contains an expression var size = ( 20 * 3 ); The syntax (rule) for an assignment statement is: variable name = expression Expression

Expressions An expression is a valid unit of code that evaluates to a value Typically takes the form – Valuevar message = "hello"; – Arithmetic Expressionvar total = ; – String Expressionvar name = "Bill" + "Smith"; – Function callvar age = prompt("Enter age:");

Expressions (cont) An expression is a valid unit of code that evaluates to a value An expression is always evaluated and the result is assigned to the variable var x = 20 + ( 0.5 * 18 ); var x = 29;

Expressions (cont) Variable names used in an expression are replaced with the current value of the variable var length = 5; var width = 20; var perimeter = 2 * ( length + width ); var perimeter = 2 * ( ); var perimeter = 50; The expression on the right-side of the assignment statement is always evaluated first

Expressions (cont) The same variable can be used on both sides of an assignment statement var x = 12; x = x + 15; x = ; x = 27; The expression on the right-side of the assignment is evaluated first When a variable name is used in an expression, the current value of the variable is used

Expressions (cont) An expression is always evaluated and the result is assigned to the variable var user = "Susan"; var name = "Hello " + user; var name = "Hello Susan"; When a variable name is used in an expression, the current value of the variable is used

Expressions (cont) When the expression is a method (function), the result of the function is assigned to the variable var color = window.prompt("Enter favorite color:"); var color = "peach"; The result of the window.prompt() method will be returned and assigned to the variable

Expressions Exercise Given the variable assignments, and expression below, identify the result of the expression that will be assigned to the variable: VARIABLEEXPRESSIONRESULT a = 10, b = 20a = a * b count = 100count = count + 20 a = "big", b = "cat"a = a + b

Global Properties and Functions The JavaScript language defines global properties and functions that can be used in JavaScript programs – global refers to the scope, or places within the code where the properties and functions can be used – global scope means the properties and functions can be used anywhere

parseInt() Global Function A common task in JavaScript programs is converting a string value into a numeric value This is needed when we prompt the user for a numeric value through the window.prompt() method – window.prompt() returns a string value – Use parseInt() function to convert a string value into a numeric integer value

parseInt() Global Function (cont) Examples: parseInt( 62 ) // returns 62 parseInt( ) // returns 85 parseInt( "100 days of summer" ) // returns 100 parseInt( "7" ) // returns 7

parseInt() Global Function (cont) We will use the parseInt() function along with the window.prompt() method Specifically, we will pass the result of the window.prompt() method to the parseInt() function var x = parseInt( window.prompt("Enter rating [1-5]:") ); In evaluating this expression, the innermost function is evaluated first 1 2

parseInt() Global Function (cont) var x = parseInt( window.prompt("Enter rating [1-5]:") ); var x = parseInt( "4" ); var x = 4

parseFloat() Global Function parseFloat() is used to convert a string value into a numeric floating point (real) number Also will be used in conjunction with the window.prompt() method Examples: parseFloat( 1.25 ) // returns 1.25 parseFloat( "5.009" ) // returns parseFloat( ".52ab" ) // returns 0.52