10 November JavaScript. Presentation Hints What do YOU think makes a good presentation Some of my suggestions Don’t write full sentences on slides Talk,

Slides:



Advertisements
Similar presentations
Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
Advertisements

Chapter 17 Fundamental Concepts Expressed in JavaScript.
Javascript Essentials How do I write it??  Start Homesite  Between the start and end BODY tags type: 
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
25 October Conditionals and Loops. Presentations Brendan: Cyberwarfare Casey: Online shopping (No current event today)
Data types and variables
29 November JavaScript: Arrays and Iterations Functions.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
JavaScript, Fourth Edition
Chapter 2 Data Types, Declarations, and Displays
Chapter 2: Introduction to C++.
JavaScript, Third Edition
Chapter 17 Fundamental Concepts Expressed in JavaScript.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements II.
1 MATERI PENDUKUNG OPERATOR Matakuliah: M0074/PROGRAMMING II Tahun: 2005 Versi: 1/0.
Admin Office hours 2:45-3:15 today due to department meeting if you change addresses during the semester, please unsubscribe the old one from the.
Copyright 2008 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
Computer Science 1000 Spreadsheets II Permission to redistribute these slides is strictly prohibited without permission.
Objectives You should be able to describe: Data Types
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
2440: 211 Interactive Web Programming Expressions & Operators.
Chapter 3: Data Types and Operators JavaScript - Introductory.
CS1 Lesson 2 Introduction to C++ CS1 Lesson 2 -- John Cole1.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
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 Session 2: What is JavaScript?
Selection Boolean What is Boolean ? Boolean is a set with only two values : –true –false true and false are standard identifiers in Pascal, called Boolean.
C++ Programming: Basic Elements of C++.
Knowledge Base C++ #include using std namespace; int main(){} return 0 ; cout
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
VBScript Language. What is VBScript Based on the Visual Basic family of languages Supports object oriented features Interpreted Loosely Typed Implicitly.
Copyright 2008 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X1 Chapter 3 Control Statements.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
Chapter 2 Variables.
CHAPTER 2 C++ SYNTAX & SEMANTICS #include using namespace std; int main() { cout
COMP Primitive and Class Types Yi Hong May 14, 2015.
Copyright 2010 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
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.
1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
C++ for Engineers and Scientists Second Edition
Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 17 JavaScript.
1 Variables and Arithmetic Operators in JavaScript.
What are Operators? Some useful operators to get you started.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Chapter 2 Variables.
Chapter 6 JavaScript: Introduction to Scripting
Fluency with Information Technology
Overview: Programming Concepts
Building Java Programs Chapter 2
Chapter 17 JavaScript.
Chapter 8 JavaScript: Control Statements, Part 2
Chapter 2 Variables.
T. Jumana Abu Shmais – AOU - Riyadh
Building Java Programs Chapter 2
Chapter 2: Introduction to C++.
Chapter 2 Programming Basics.
Boolean Expressions to Make Comparisons
Building Java Programs
Building Java Programs
Javascript Chapter 19 and 20 5/3/2019.
Building Java Programs Chapter 2
Chapter 2 Variables.
Building Java Programs
Presentation transcript:

10 November JavaScript

Presentation Hints What do YOU think makes a good presentation Some of my suggestions Don’t write full sentences on slides Talk, don’t read Pictures when possible If you ask a question, wait 30 seconds

Defining a Variable Statement used is called a declaration Format: var name = value; name is the identifier value is the initial value given to the variable Variable Names The language is case sensistive yourname, Yourname, YourName are three different variables Recommendation: always use the same style Initial values You do not need to initialize variables Do need to give them a value before you try to do anything useful with them

Examples var TaxRate =.087; TaxRate is a variable that contains a numeric value representing the tax rate to be used and has an initial value of.087 var FirstName = “”; FirstName is a variable that contains a character string representing a person’s first name and has an initial value of nothing var done; done is variable that will track the state of ongoing work and has no initial value

Types of Data 3 types: Numeric Does not distinguish between integers and real numbers Can use either standard or scientific notation Do not use commas String Can be enclosed in either single (‘) or double (“) quotes If need to use one in the string, use the other for the whole string “” is called the empty string or the null string Boolean Two values: true, false Reserved words. Do not use as variable names

Multiple declarations Can use a separate statement for every variable or declare a list of variables var FirstName = “”, LastName = “”; var FirstName = “”; var LastName = “”; Statements are equivalent Can have some initialized and some not

Documenting Your Code Documenting your code is not necessary for the compiler or interpreter, but is typically needed by people – including yourself! ALWAYS document what you write Information for people only are comments

Comments Two Forms /* … */ // /* … */ Everything between the delimiters is a comment and not processed Can cross multiple lines Can start anywhere // Everything from there until the end of the line is not processed

var start = 0; // beginning of the string var start = 0; /* identifies the place to start processing */ var start = 0; /* beginning of the string var end = 0; Comment Examples WRONG RIGHT

What to do with Variables Simplest action is to assign a value: assignment statement Name = “Tom”; Price = 13.25; Can use any type of expression on the right – both constants and variables

Expressions: Arithmetic There are rules of precedence 1+b*c Do I multiply or add first? If you use parentheses, you don’t have to remember! Binary operations +, -, /, *, % (modulus or remainder) Unary operations Negation

Expressions: String Primary one is concatenation Uses “+” If either operand is a string, means concatenate Else means add

Expressions: Boolean Comparisons Numeric or string >, <, == Not and combinations Logical operations And, or, not

Logical Tables 0 = false, 1 = true And 0 && 0 = 0 0 && 1 = 0 1 && 0 = 0 1 && 1 = 1 Or 0 || 0 = 0 0 || 1 = 1 1 || 0 = 1 1 || 1 = 1 Not !0 = 1 !1 = 0

Practice Write a statement that computes total price including tax and shipping computes the area of a circle calculates the average speed of a car trip

Using statements in forms An example: Shots: <input name="shots“ onclick="num_shots= 1" type="radio"> 1 <input name="shots" onclick="num_shots = 2" type="radio"> 2

How to Change What You Do Conditional statements Iterations (doing it more than once) Functions (an algorithm that can be executed more than once) All need compound statements – multiple statements that can be processed as one { stmt; stmt; stmt; }

But first, JavaScript in Your Browser Simple JavaScript in body … code … Simplest statement document.write(“text string")

Separating Functions & Forms We’ll separate forms and functions Separate out all the actions that we will do Put them in the header Simpler forms In the … variable definitions … … functions ….