Announcements Due dates Project 1B—Wednesday by 10pm 1-1-1 rule Thursday by 10pm Only once during quarter! Lab 5—Friday by 10pm Next week Labs 6/7—Tuesday.

Slides:



Advertisements
Similar presentations
Chapter 17 Fundamental Concepts Expressed in JavaScript.
Advertisements

1 Outline 13.1Introduction 13.2A Simple Program: Printing a Line of Text in a Web Page 13.3Another JavaScript Program: Adding Integers 13.4Memory Concepts.
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)
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Fundamental Concepts Expressed in JavaScript Get with the Program lawrence.
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,
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
JavaScript, Fourth Edition
JavaScript, Third Edition
Chapter 17 Fundamental Concepts Expressed in JavaScript.
The Information School of the University of Washington Oct 20fit programming1 Programming Basics INFO/CSE 100, Fall 2006 Fluency in Information Technology.
JavaScript – Part II Data Types and Operations George Mason University June 3, 2010.
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
2440: 211 Interactive Web Programming Expressions & Operators.
Chapter 3: Data Types and Operators JavaScript - Introductory.
CSE 1301 Lecture 2 Data Types Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
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?
Input, Output, and Processing
C Derived Languages C is the base upon which many build C++ conventions also influence others *SmallTalk is where most OOP comes Java and Javascript have.
20-753: Fundamentals of Web Programming 1 Lecture 12: Javascript I Fundamentals of Web Programming Lecture 12: Introduction to Javascript.
1 Chapter 18 Programming Basics When it comes to being precise about an algorithm, a programming language is better than English.
ITBP 119 Algorithms and Problem Solving Section 2.1 Installing software Section 2.2 First Programs Section 2.3 Variables.
JavaScript Syntax and Semantics. Slide 2 Lecture Overview Core JavaScript Syntax (I will not review every nuance of the language)
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 5, Lecture 1 (Monday)
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
 2000 Deitel & Associates, Inc. All rights reserved. Outline 8.1Introduction 8.2A Simple Program: Printing a Line of Text in a Web Page 8.3Another JavaScript.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Announcements CLUE Tutoring Wednesday nights 7-8:30PM MGH extra-credit points for each session you attend from last week through the end of the quarter.
1 Server versus Client-Side Programming Server-SideClient-Side.
Data And Variables Chapter Names vs. Values Michael Jordan name (the letter sequence used to refer to something) value (the thing itself)
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Fluency with Information Technology Third Edition by Lawrence Snyder Chapter.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
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.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 17 JavaScript.
Fluency with Information Technology INFO100 and CSE100 Katherine Deibel Katherine Deibel, Fluency in Information Technology1.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
REEM ALMOTIRI Information Technology Department Majmaah University.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Topics Designing a Program Input, Processing, and Output
Chapter 6 JavaScript: Introduction to Scripting
Fluency with Information Technology
Overview: Programming Concepts
Introduction to Scripting
JavaScript Syntax and Semantics
Expressions and Control Flow in JavaScript
JavaScript.
Chapter 17 JavaScript.
WEB PROGRAMMING JavaScript.
Lecture 2 Python Programming & Data Types
Introduction to JavaScript
INFO/CSE 100, Spring 2005 Fluency in Information Technology
PHP.
T. Jumana Abu Shmais – AOU - Riyadh
Lecture 2 Python Programming & Data Types
Boolean Expressions to Make Comparisons
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Javascript Chapter 19 and 20 5/3/2019.
CIS 136 Building Mobile Apps
Lecture 9: JavaScript Syntax
Presentation transcript:

Announcements Due dates Project 1B—Wednesday by 10pm rule Thursday by 10pm Only once during quarter! Lab 5—Friday by 10pm Next week Labs 6/7—Tuesday by 10pm 1/5/2016D.A. Clements, MLIS, UW iSchool 1

Announcements Vocabulary for the week was posted in GoPost Reading Ch 18 for today Ch 21 for Friday 1/5/2016D.A. Clements, MLIS, UW iSchool 2

Basic Programming Concepts Get with the Program D.A. Clements D.A. Clements, MLIS, UW iSchool 3 1/5/2016

Objectives Learn basic programming concepts common to all programming languages Apply them to Web pages using JavaScript We’ll spend a couple weeks on this journey D.A. Clements, MLIS, UW iSchool 4 1/5/2016

Documenting your code with comments Data types (math, string, boolean) Variables Assigning values to variables Expressions Conditionals, branches, or tests (all names for same thing) Loops, or iterations (both names for same thing) Arrays, lists, or collections (all names for same thing) Functions and Methods Basic Programming Concepts D.A. Clements, MLIS, UW iSchool 5 1/5/2016

Programming Concepts Basic concepts have been developed over last 50 years to simplify common programming tasks Programming concepts will be implemented in JavaScript in this course Easy syntax Immediate results No special software required beyond NotePad++ All the major browsers include JavaScript interpreters D.A. Clements, MLIS, UW iSchool 6 1/5/2016

DATA TYPES Currency, string, number, boolean, date/time D.A. Clements, MLIS, UW iSchool 7 1/5/2016

Strings The quick brown fox jumped over the lazy dog. D.A. Clements, MLIS, UW iSchool 8 1/5/2016

String = a sequence of keyboard characters Always surrounded by single ( ' ' ) or double quotes ( " " ) No smart quotes! (“ ” and ‘ ’) Initialize a declaration var hairColor = "black"; Quotes can nest firstLine = “Johnson called, ‘Dude!’ ”; Strings D.A. Clements, MLIS, UW iSchool 9 1/5/2016

Strings Any number of characters allowed in a string Minimum number of characters is none ( "" ) the empty string D.A. Clements, MLIS, UW iSchool 10 1/5/2016

Strings How are they stored in the computer? Quotes are removed (they are only used to 'delimit' the string literal) Delimit means to mark the start and end of the literal 1/5/2016D.A. Clements, MLIS, UW iSchool 11

Numbers Rules for Writing Numbers No "units" or commas NOT $5,884,559 Up to 10 significant digits Range from to D.A. Clements, MLIS, UW iSchool 12 1/5/2016

Boolean Values Two logical values: True and False They are values, not identifiers or strings Used implicitly throughout programming process; only occasionally for initializing variables Mostly used to compare data or make decisions 1/5/2016D.A. Clements, MLIS, UW iSchool 13

VARIABLES What’s in a name? D.A. Clements, MLIS, UW iSchool 14 1/5/2016

Names, Values, and Variables Names in a Program Are Called Identifiers Variables store values and give you a handy way to refer to the current value in the variable Like we say “The President” to refer to our current president Names Have Changing Values U.S. President current value is George W. Bush previous values were Bill Clinton, George Washington D.A. Clements, MLIS, UW iSchool 15 1/5/2016

Variables Variables are named areas in memory We can refer to the value in the memory area without knowing its value, just by calling its name 1/5/ D.A. Clements, MLIS, UW iSchool

In a restaurant, each table is numbered. All night long the people and the food served at the table change, but the table still has the same number. That table number functions like a variable name. Variables 1/5/ D.A. Clements, MLIS, UW iSchool 6:40pm 7:30pm 8:20pm 9:00pm 6pm

Quick Clicks One question

Identifiers and Their Rules ValidInvalidReason It’s Invalid firstone1stOneBegins with number first1 first-1JS thinks hyphen is a minus sign firstOnefirst$1$ not allowed first_onefirst OneSpace not allowed first_1First1!Exclamation point D.A. Clements, MLIS, UW iSchool 19 Case sensitive: HOME ≠ Home ≠ home 1/5/2016

Quick Clicks Two questions

VARIABLE DECLARATIONS Example: var home; D.A. Clements, MLIS, UW iSchool 21 1/5/2016

Declare your variables at the top of your script so you can find them easily State what variables will be used Computer sets aside a named area in memory for each variable Declare each variable only once in your program The declaration is a type of statement Command is the word var For example, a program to calculate area of circle given radius, needs variables area and radius: var radius, area; Variable Declaration Statement D.A. Clements, MLIS, UW iSchool 22 1/5/2016

The Statement Terminator A program is a list of statements End each statement with the statement terminator symbol In JavaScript, all statements terminate with the semicolon ( ; ) D.A. Clements, MLIS, UW iSchool 23 1/5/2016

Quick Clicks One question

Rules for Declaring Variables D.A. Clements, MLIS, UW iSchool 25 Declare every variable before it is used in the program In JavaScript declaration can be anywhere in the program Best practice: Place them at the top of the program Declare each variable only once in the program Undefined values Variable has been declared but does not yet have a value var number1;// undefined value var number2 = 42;// initialized to the value 42 1/5/2016

ASSIGNING VALUES TO VARIABLES All about assignment statements 1/5/2016D.A. Clements, MLIS, UW iSchool 26

Assign values to variables with an assignment operator. We'll use = for now. var yourAge, acctBal, custName; yourAge = 32;//store 32 in yourAge acctBal = ;//store in acctBal custName = 'Jeff';//store 'Jeff" in custName isCustomer = true;//store boolean true in isCustomer (no quotes) Var yourName = 'Jeff'//alternate all-in-one line assignment statement Assigning Values to Variables 1/5/2016D.A. Clements, MLIS, UW iSchool 27

Assignment Statement Flow moves from right to left. Results of the replace the value stored in the. 9/24/2008D.A. Clements, MLIS28

Assigning Values to Variables and Variables to Variables We can also assign one variable to another: LineAssignment StatementmyNameyourName 1var yourName = "Sarah"; 2var myName = "Andrea"; 3yourName = myName; 4yourName = "myName"; 9/24/2008D.A. Clements, MLIS29

Assigning Values to Variables and Variables to Variables We can also assign one variable to another: LineAssignment StatementmyNameyourName 1var yourName = "Sarah";Sarah 2var myName = "Andrea"; 3yourName = myName; 4yourName = "myName"; 9/24/2008D.A. Clements, MLIS30

Assigning Values to Variables and Variables to Variables We can also assign one variable to another: LineAssignment StatementmyNameyourName 1var yourName = "Sarah";Sarah 2var myName = "Andrea";Andrea 3yourName = myName; 4yourName = "myName"; 9/24/2008D.A. Clements, MLIS31

Assigning Values to Variables and Variables to Variables We can also assign one variable to another: LineAssignment StatementmyNameyourName 1var yourName = "Sarah";Sarah 2var myName = "Andrea";AndreaSarah 3yourName = myName; 4yourName = "myName"; 9/24/2008D.A. Clements, MLIS32

Assigning Values to Variables and Variables to Variables We can also assign one variable to another: LineAssignment StatementmyNameyourName 1var yourName = "Sarah";Sarah 2var myName = "Andrea";AndreaSarah 3yourName = myName;Andrea 4yourName = "myName"; 9/24/2008D.A. Clements, MLIS33

Assigning Values to Variables and Variables to Variables We can also assign one variable to another: LineAssignment StatementmyNameyourName 1var yourName = "Sarah";Sarah 2var myName = "Andrea";AndreaSarah 3yourName = myName;Andrea 4yourName = "myName"; 9/24/2008D.A. Clements, MLIS34

Assigning Values to Variables and Variables to Variables We can also assign one variable to another: LineAssignment StatementmyNameyourName 1var yourName = "Sarah";Sarah 2var myName = "Andrea";AndreaSarah 3yourName = myName;Andrea 4yourName = "myName";Andrea 9/24/2008D.A. Clements, MLIS35

Assigning Values to Variables and Variables to Variables We can also assign one variable to another: LineAssignment StatementmyNameyourName 1var yourName = "Sarah";Sarah 2var myName = "Andrea";AndreaSarah 3yourName = myName;Andrea 4yourName = "myName";AndreamyName 9/24/2008D.A. Clements, MLIS36

Other Assignment Operators LineAssignment StatementValue in myAge 1var myage = 32; 2myAge = myAge + 2; 3myAge += 2; 4myAge ++; 5myAge -= 3; 6myAge -- ; 9/24/2008 D.A. Clements, MLIS 37

Other Assignment Operators LineAssignment StatementValue in myAge 1var myage = 32;32 2myAge = myAge + 2; 3myAge += 2; 4myAge ++; 5myAge -= 3; 6myAge -- ; 9/24/2008 D.A. Clements, MLIS 38

Other Assignment Operators LineAssignment StatementValue in myAge 1var myage = 32;32 2myAge = myAge + 2;34 3myAge += 2; 4myAge ++; 5myAge -= 3; 6myAge -- ; 9/24/2008 D.A. Clements, MLIS 39

Other Assignment Operators LineAssignment StatementValue in myAge 1var myage = 32;32 2myAge = myAge + 2;34 3myAge += 2;36 4myAge ++; 5myAge -= 3; 6myAge -- ; 9/24/2008 D.A. Clements, MLIS 40

Other Assignment Operators LineAssignment StatementValue in myAge 1var myage = 32;32 2myAge = myAge + 2;34 3myAge += 2;36 4myAge ++;37 5myAge -= 3; 6myAge -- ; 9/24/2008 D.A. Clements, MLIS 41

Other Assignment Operators LineAssignment StatementValue in myAge 1var myage = 32;32 2myAge = myAge + 2;34 3myAge += 2;36 4myAge ++;37 5myAge -= 3;34 6myAge -- ; 9/24/2008 D.A. Clements, MLIS 42

Other Assignment Operators LineAssignment StatementValue in myAge 1var myage = 32;32 2myAge = myAge + 2;34 3myAge += 2;36 4myAge ++;37 5myAge -= 3;34 6myAge -- ;33 9/24/2008 D.A. Clements, MLIS 43

EXPRESSIONS Calculating values in variables 1/5/2016D.A. Clements, MLIS, UW iSchool 44

An Expression and its Syntax Algebra-like formula called an expression Built out of values and operators Standard arithmetic operators are symbols of basic arithmetic 1/5/2016D.A. Clements, MLIS, UW iSchool 45

Arithmetic Operators Multiplication must be given explicitly with the asterisk ( * ) multiply operator Multiply and divide are performed before add and subtract Anything within parentheses is calculated first Within parentheses multiply and divide are performed first JavaScript does not have an operator for exponents 1/5/2016D.A. Clements, MLIS, UW iSchool 46

Relational Operators Make comparisons between numeric values Used in if statements and stop tests in loops Outcome is a Boolean value, true or false <less than <=less than or equal to ==equal to !=not equal to >=greater than or equal to >greater than Note: Difference between = and == == compares values = assigns a value to a variable 1/5/2016D.A. Clements, MLIS, UW iSchool 47

Logical Operators To test two or more relationships at once Teenagers are older than 12 and younger than 20 Logical AND Operator is && Outcome of a && b is true if both a and b are true; otherwise it is false Logical OR Operator is || Outcome of a || b is true if either a is true or b is true Logical NOT Operator is ! Unary operator. Outcome is opposite of value of operand 1/5/2016D.A. Clements, MLIS, UW iSchool 48

More about the + operator Addition Adds numbers produces 9 Concatenation Glues strings together "four" + "five" produces "fourfive“ "four" + “5" produces "four5" "four " + "five" produces "four five" 1/5/2016D.A. Clements, MLIS, UW iSchool 49

Quick Clicks Two questions

DOCUMENTING YOUR CODE Comments and White Space 1/5/ D.A. Clements, MLIS, UW iSchool

//Single-line JavaScript comment /*Multi-line JavaScript comment continues for more than one line*/ Comments allow you to Annotate your code Remind yourself what you did and why Notes for yourself—or someone else—six months from now when you’re making an update! Comments 1/5/2016D.A. Clements, MLIS, UW iSchool 52

End papers… Eagleson's law Any code of your own that you haven't looked at for six or more months might as well have been written by someone else. 1/5/ D.A. Clements, MLIS, UW iSchool

White Space White space is your friend! The statements may be run together on a single line Use white space to help you read your code understand your program 1/5/ D.A. Clements, MLIS, UW iSchool

Announcements Read chapter 20 for Friday