ITBP 119 Algorithms and Problem Solving Section 2.1 Installing software Section 2.2 First Programs Section 2.3 Variables.

Slides:



Advertisements
Similar presentations
Introducing JavaScript
Advertisements

Computer Programming w/ Eng. Applications
Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
1 CSC 551: Web Programming Spring 2004 client-side programming with JavaScript  scripts vs. programs  JavaScript vs. JScript vs. VBScript  common tasks.
The Web Warrior Guide to Web Design Technologies
Introduction to C Programming
 2005 Pearson Education, Inc. All rights reserved Introduction.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Mathematical Operators  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming in.
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
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.
The Information School of the University of Washington Oct 20fit programming1 Programming Basics INFO/CSE 100, Fall 2006 Fluency in Information Technology.
2012 •••••••••••••••••••••••••••••••••• Summer WorkShop Mostafa Badr
Introduction to scripting
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
WEB DESIGN AND PROGRAMMING Introduction to Javascript.
Adding JavaScript (<script tag>)
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
Introduction to Python
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
Week 9 PHP Cookies and Session Introduction to JavaScript.
2440: 211 Interactive Web Programming Expressions & Operators.
Chapter 4 JavaScript and Dynamic Web pages. Objectives Static Web pages Dynamic Web pages JavaScript Variables Assignments. JavaScript Functions –(prompt(“”,””)
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
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?
Tutorial 10 Programming with JavaScript
CIS 260: App Dev I. 2 Programs and Programming n Program  A sequence of steps designed to accomplish a task n Program design  A detailed _____ for implementing.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Variables, Functions and Events (there is an audio component to this eLesson) © Dr.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
JavaScript Programming Unit #1: Introduction. What is Programming?
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
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.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
REVIEW No curveballs this time …. PROBLEM TYPE #1: EVALUATIONS.
Variables and Assignment CSIS 1595: Fundamentals of Programming and Problem Solving 1.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
1 Server versus Client-Side Programming Server-SideClient-Side.
Making dynamic pages with javascript Lecture 1. Java script java versus javascript Javascript is a scripting language that will allow you to add real.
Programming with Microsoft Visual Basic th Edition
Python Let’s get started!.
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.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
PHP Form Processing * referenced from
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
Expressions and Data Types Professor Robin Burke.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
 2001 Prentice Hall, Inc. All rights reserved. Outline 1 JavaScript.
Chapter 6 JavaScript: Introduction to Scripting
Tutorial 10 Programming with JavaScript
Python Let’s get started!.
JavaScript is a programming language designed for Web pages.
Value-Returning Functions
Variables, Expressions, and IO
JavaScript Fundamentals
JavaScript and Ajax (Expression and Operators)
WEB PROGRAMMING JavaScript.
PHP.
T. Jumana Abu Shmais – AOU - Riyadh
Tutorial 10 Programming with JavaScript
Tutorial 10: Programming with javascript
JavaScript Basics What is JavaScript?
Chapter 2 Primitive Data Types and Operations
Programming Basics Review
Presentation transcript:

ITBP 119 Algorithms and Problem Solving Section 2.1 Installing software Section 2.2 First Programs Section 2.3 Variables

outline Installation of the software Writing you first programs Doing VS Asking Function Literals Assignment Statements –Variables Declaration and Initialization –Expressions –Variable Naming Function Parameter Evaluation

Installing Arachnophilia 4.0 Make a folder APS under My Documents and use it to store all files for this course. Download the zip file Arachnophilia from the Blackboard Unzip the file Double click on the file arach_full.exe Follow the instructions

Installing Arachnophilia 4.0 Set the preview browser to the internal browser

Creating, editing, previewing HTML files Create new HTML page edit the title Add new header Add an image Change the size of the image

First Program The use of alert and prompt Let’s write a program that prompt the user with her name and the computer will greet that name by saying: hello ….. Remember to be in the frames mode so that you can reduce the amount of typing.

Important concepts Script Comment Alert Prompt Function parameters Function return values Java script is case sensitive

Doing Vs. Asking Functions alert: alert( “hello World !!!”); –doing function in which you are asking the function to do some task and return nothing –Void function prompt: var age = prompt (“enter your age”, “20”); –Asking function: in which you are asking the function to do some task and return a value. –Return values are normally assigned to a variable otherwise it will be discarded.

Doing Vs. Asking Functions alert ( “ hello World “ ) ; var age = prompt ( “ enter age: “, “20” ) ; parameters Return value Function name void function prompt ( “ enter age: “, “20” ) ; Is this wrong?

Literals By literal we mean any number, text, boolean or other information that represents a value. Example: “ It’s true that ‘ is a literal” 2008 “ today is 2 / 9 /2008 “ true “ “ “ here I include double quote \” as part of the literal” String Literals are specified in programs with double quotes “” Number and boolean literals are NOT specified by double quotes “”. Boolean means either true or false value.

Assignment Statements var Variable = expression –Variables are named memory cells. –A variable contains a value thus you write person Hind to indicate that the variable person contains the value "Hind". Hind Person Variable Memory location contains the value Hind Value stored in The memory location var person = “Hind” ;

Assignment Statements var Variable = expression –Expression: any literal value, or a mathematical/logical expression. –Example of expressions: var X = 10; var Y = 100; X + Y var L = true var name = “your Name “; var L2 = X < Y && Y != X ; var X2 = X * X + Y * Y * Y / ;

Assignment Statements/Evaluation response = “Samira” ; message = “hello “ + response ; message = “Hello “ + response ; Samira Hello Samira Samira Hello Samira response message RHS LHS

Assignment Evaluation The Right Hand side of the assignment is evaluated/calculated first. The right hand side value is assigned to the left hand side of the assignment. The left hand side of the assignment must be always a variable (or none). –var “xyz” = 12;  wrong declaration –var x + 10 = y;  wrong declaration

Exercise Given the following variables var month = “September” ; var year = 2008 ; var day = 2 ; Calculate the value of each variable in the following assignment statements. 1.tomorrow = day + 1; 2.lastYear = year – 1; 3.var date1 = day + month + year ; 4.var date2 = day + “ month “ + year; 5.date3 = day + month + “ year “; 6.date4 = “ day ” + month + year;

Exercise** Given the following variables var x = “ hello ” ; var y = 2008 ; var z = 2 ; Calculate the value of each variable in the following assignment statements. 1.var w = z + 1; 2.y = y / ; 3.y = y – 1; 4.var d = x + y ; 5.var d2 = x + y + x + “ again ”; 6.var d3 = x + “ d2 “; 7.z + 1 ; 8.var d4 = z * 5 ;

Assignment Statements Which of the following is correct assignment and why? 1.var “salim” = 10; 2.var salim ; 3. var age = 22; var newAge = 11; age + 10 = newAge ;

More about Variables / Variable Names Variable Names: the rules of java script state the following about variable names: –The name of the variable cannot be the same as any of the language keywords. –Variable name can be any sequence of numeric, alphabet, or the special characters _, $ –Variable name should only start with alphabet,under score _, or $. –Variables are case sensitive

Exercise Example: identify the correctness of the following variables names. 1.var my_age = 25; 2.var _myAge = 22; 3.var TODAY = “4/9/2008” ; 4.var $amir_ = “ SAMIR” ; 5.var alert = ; 6.var Alert = 10.2 ; 7.var prompt = “ prompt me please “; 8.var salim%ali = true ; 9.var 1foo = false;

Function Parameter Evaluation The parameter of a function can be an expression. If the parameter is an expression then it is evaluated/calculated first and then it is passed to the function.

Function Parameter Evaluation Example: var x =10; alert( x + 10 ); 1.The parameter of the function alert is the expression x Before the alert is run, the computer computes the value of the expression which is x+1 = = 11 3.The value 11 is passed to the alert.

Exercise Which of the following are literals and which are variables? 1.“Fatima” 2._salim 3.dateOfBirth “12343” 6.“3.14” Pi

Exercise Given the following two variables, what is the difference between the following: var name = “zena” var friend = “hoda” name = friend ;name = “ friend “;

Initialization and Declaration Declaration of a variable: is a way to give a name to some memory location. –Use the keyword var to declare a variable –There will be No initial value in the memory Example: variable declarations var age ; var name ; var firstName, lastName ;

Initialization and Declaration Initialization of variable: Storing a value in the variable. –Example: var age; var name ; var firstName, lastName; age = 10; name = “Mahir”; firstName = “Salwa”; lastName = name; declarations initialization

Initialization and Declaration We can initialize a variable while declaring it Example: var age = 10; var name = “Mahir” ; var firstName = “Salwa”, lastName= name ;

Exercises What will be the output of the alert function in the following (explain your answers) … var name = “alia”; alert(name); name =prompt(“ enter name:”, “salma”); alert(name); …

Exercises What will be the output of the alert function in the following (explain your answers) … var name = “alia”; prompt(“ enter name:”, “salma”); alert(name); …

Exercises What will be the output of the alert function in the following (explain your answers) … var name ; var fName=prompt(“ enter name:”, “salma”); alert(name); alert(fName); …

Exercises What will be the output of the alert function in the following (explain your answers) … var fName=prompt(“ enter name:”, “salma”); var msg1 = “hello” + fName; alert( msg1); var msg2 = “welcome “ + “fName” ; alert( msg2); …

Exercises What will be the output of the alert function in the following (explain your answers) … var x = “salam” ; var msg1 = “hello ” + x ; alert( msg1); x = x + “ alaykum “; alert( x); …

Exercises What will be the output of the alert function in the following (explain your answers) … var x = 10 ; alert( x); x = x * 10 ; alert( x); x = x / 20; alert(x); …