Programming with JavaScript CSc 2320 Fall 2014 Disclaimer: All words, pictures are adopted from “Simple JavaScript”by Kevin Yank and Cameron Adams and.

Slides:



Advertisements
Similar presentations
Assembly Language for x86 Processors 6th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy this slide.
Advertisements

CS0004: Introduction to Programming Repetition – Do Loops.
Objectives Using functions to organize PHP code
JavaScript Part for Repetition Statement for statement Cpecifies each of the items needed for counter-controlled repetition with a control variable.
PHP Functions and Control Structures. 2 Defining Functions Functions are groups of statements that you can execute as a single unit Function definitions.
ITC 240: Web Application Programming
Tutorial 12 Working with Arrays, Loops, and Conditional Statements
Chapter 8 (Control Structure) Slide 1 Control Structures Control structures are used by the programmer to incorporate the desired sequence of execution.
Chapter 4 Functions and Control Structures PHP Programming with MySQL.
© The McGraw-Hill Companies, 2006 Chapter 5 Arrays.
Chapter 8: Introduction to High-level Language Programming Invitation to Computer Science, C++ Version, Third Edition.
CS 117 Spring 2002 Review for Exam 2 March 6, 2002 open book, 1 page of notes.
Topic R3 – Review for the Final Exam. CISC 105 – Review for the Final Exam Exam Date & Time and Exam Format The final exam is 120-minutes, closed- book,
1 CSC 1401 S1 Computer Programming I Hamid Harroud School of Science and Engineering, Akhawayn University
Guide To UNIX Using Linux Third Edition
Introduction to JavaScript for Python Programmers
TODAY’S LECTURE Review Chapter 2 Go over exercises.
CIS3931 – Intro to JAVA Lecture Note Set 3 19-May-05.
1 CSC 221: Computer Programming I Fall 2004 course overview  what did we set out to learn?  what did you actually learn?  where do you go from here?
JS Arrays, Functions, Events Week 5 INFM 603. Agenda Arrays Functions Event-Driven Programming.
Chapter 4 Chapter 4 Creating a Simple Page Disclaimer: All words, pictures are adopted from “Learning Web Design (3rdeds.)” by Jennifer NiederstRobbins,
Arrays – What is it? – Creation – Changing the contents Functions – What is it? – Syntax – How they work – Anonymous functions A quick lesson in Objects.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
Principles of Programming - NI July Chapter 5: Structured Programming In this chapter you will learn about: Sequential structure Selection structure.
CSEB 114: PRINCIPLE OF PROGRAMMING Chapter 5: Structured Programming.
Project 1 Due Date: September 25 th Quiz 4 is due September 28 th Quiz 5 is due October2th 1.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
PHP Programming with MySQL Slide 4-1 CHAPTER 4 Functions and Control Structures.
CPS120: Introduction to Computer Science Decision Making in Programs.
Chapter 2 Functions and Control Structures PHP Programming with MySQL 2 nd Edition.
Browser Object Model& Debugging CSc 2320 Fall 2014 Disclaimer: All words, pictures are adopted from “Simple JavaScript”by Kevin Yank and Cameron Adams.
sequence of execution of high-level statements
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
Coding Design Tools Rachel Gauci. Task: Counting On Create a program that will print out a sequence of numbers from "1" to a "number entered”. Decision’s.
PHP Constructs Advance Database Management Systems Lab no.3.
Events and Animations CSc 2320 Fall 2014 Disclaimer: All words, pictures are adopted from “Simple JavaScript”by Kevin Yank and Cameron Adams and also from.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
Control Structures sequence of execution of high-level statements.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 5 Looping.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
JavaScript, Fourth Edition
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Lecture 26: Reusable Methods: Enviable Sloth. Creating Function M-files User defined functions are stored as M- files To use them, they must be in the.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
General Computer Science for Engineers CISC 106 Lecture 12 James Atlas Computer and Information Sciences 08/03/2009.
Working with Loops, Conditional Statements, and Arrays.
Introduction to JavaScript CSc 2320 Fall 2014 Disclaimer: All words, pictures are adopted from “Simple JavaScript”by Kevin Yank and Cameron Adams and also.
Rich Internet Applications 2. Core JavaScript. The importance of JavaScript Many choices open to the developer for server-side Can choose server technology.
Document Object Model CSc 2320 Fall 2014 Disclaimer: All words, pictures are adopted from “Simple JavaScript”by Kevin Yank and Cameron Adams and also from.
Chapter Looping 5. The Increment and Decrement Operators 5.1.
A High Flying Overview CS139 – Fall 2006 How far we have come.
XP Tutorial 3 New Perspectives on JavaScript, Comprehensive1 Working with Arrays, Loops, and Conditional Statements Creating a Monthly Calendar.
JavaScript, Sixth Edition
JavaScript Modularity. Goals By the end of this lecture, you should … Understand why programmers use modularity. Understand how to create a function in.
Introduction to Javascript. What is javascript?  The most popular web scripting language in the world  Used to produce rich thin client web applications.
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
Chapter 5 Murach's JavaScript and jQuery, C1© 2012, Mike Murach & Associates, Inc.Slide 1.
Today… Preparation for doing Assignment 1. Invoking methods overview. Conditionals and Loops. Winter 2016CMPE212 - Prof. McLeod1.
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
CS0004: Introduction to Programming
Exam 2 Review.
CHAPTER 4 CLIENT SIDE SCRIPTING PART 3 OF 3
JavaScript: Control Statements.
Loop Control Structure.
Chapter 8 JavaScript: Control Statements, Part 2
PHP.
Objectives In this chapter, you will:
Chapter 8 JavaScript: Control Statements, Part 2
Presentation transcript:

Programming with JavaScript CSc 2320 Fall 2014 Disclaimer: All words, pictures are adopted from “Simple JavaScript”by Kevin Yank and Cameron Adams and also from W3schools. Edited by Guoliang Liu, Only for Course CSc2320 at GSU CS Department

In this chapter Programming with JavaScript ◦ Conditions and Loops: Controlling Program Flow ◦ Functions ◦ Objects

Conditions If Statements Flow chart for If statement:

Conditions(cont.) E.g.

Conditions(cont.) Multiple conditions ◦ Use “&” or “||” to chain all the conditions ◦ “&”: And ◦ “||”: Or

Conditions(cont.) If-else statements

Conditions(cont.) Else-if statements E.g.

Loops While loops E.g.

Loops(cont.) Do-while loops

Loops(cont.) For loops ◦ Most popular ◦ Control structure is the same as while loops but more succinct ◦ Succinct in?  Initialization of the counter  The variation of the counter

Loops(cont.) For loops

Loops(cont.) How to stop a loop halfway? ◦ Use key word “break”; E.g. ◦ How to break this after first three repetitions. ◦ One way:  Add if(i==3){ break;} inside under the only statement.

Functions Question? ◦ What if I want to re-run some code a few times? ◦ E.g., alert function “alert()”; Function: Wrapper for a block of code ◦ All you need is put a name for the wrapper Define function using key word: “function”

Functions(cont.) Arguments: pass data to a function E.g. ◦ Definition: ◦ Call:

Functions(cont.) Arguments array A lazy way for arguments For unknown parameter length E.g.

Functions(cont.) Return statements: output data from a function. A function return the data to the statement that called it. E.g.

Functions(cont.) Return statements: output data from a function. Return is always the final action of the function (like break in loops). E.g., will the alert() pop up?

Functions(cont.) Scope: keep the variables separate Scope decides where and when a variable is alive. Scope: ◦ Global scope: Live in the program and alive until the end of the program ◦ Local scope: Live in the function and die when the function returns or ends.

Functions(cont.) E.g. for scope Name collision: ◦ Stand for where it lives ◦ E.g.

Objects Objects: Group together sets of properties and methods. ◦ Property: variable ◦ Method: function An array is a native object Create your own objects

Objects(cont.) E.g., imagine the object as an array and its content may store native or complex data types or functions.

Homework Assignment8 Search numbers in your JavaScript. ◦ Declare an array with the a sequence of numbers. E.g., following numbers in order. [9,3,4.3,24,54,8,19,23,46,87,3.14]. ◦ Task 1, pop up a window to output the index of number “23”. ◦ Task 2, pop up a single window to output all the numbers that are larger than 10. ◦ Alternatives: You better use functions to do the jobs. Like define a compare() function to test whether the current data is satisfied or not. ◦ Due date: Nov. 19 th, 2014.