CSD 340 (Blum)1 Starting JavaScript Homage to the Homage to the Square.

Slides:



Advertisements
Similar presentations
Chapter 7 JavaScript: Introduction to Scripting. Outline Simple Programs Objects and Variables Obtaining User Input with prompt Dialogs – –Dynamic Welcome.
Advertisements

/ 251 Internet Applications Ahmed M. Zeki Sem – / Chapter 8.
Chapter 3 – Designing your web pages Dr. Stephanos Mavromoustakos.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
Modifying existing content Adding/Removing content on a page using jQuery.
Lesson 12- Unit L Programming Web Pages with JavaScript.
The Web Warrior Guide to Web Design Technologies
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
CSD 340 (Blum)1 Using Microsoft Visual Studio.NET Development Environment and Introducing Functions.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Introduction to Scripting.
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.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
CIS101 Introduction to Computing Week 11. Agenda Your questions Copy and Paste Assignment Practice Test JavaScript: Functions and Selection Lesson 06,
Introduction to JavaScript. Aim To enable you to write you first JavaScript.
Introduction to scripting
Javascript and the Web Whys and Hows of Javascript.
CS346 - Javascript 1, 21 Module 1 Introduction to JavaScript CS346.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
JavaScript Tutorial 1 - Introduction to JavaScript WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Introduction to JavaScript – A First.
Dr. Qusai Abuein1 Internet & WWW How to program Chap.(6) JavaScript:Introduction to Scripting.
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
Sahar Mosleh California State University San MarcosPage 1 JavaScript Basic.
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.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
JavaScript Introduction.  JavaScript is a scripting language  A scripting language is a lightweight programming language  A JavaScript can be inserted.
CSD 340 (Blum)1 Starting JavaScript Homage to the Homage to the Square.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
HTML Overview Part 5 – JavaScript 1. Scripts 2  Scripts are used to add dynamic content to a web page.  Scripts consist of a list of commands that execute.
JavaScript Challenges Answers for challenges
JavaScript 1 COE 201- Computer Proficiency. Introduction JavaScript scripting language ▫Originally created by Netscape ▫Facilitates disciplined approach.
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.
Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing a Line of Text in a Web Page 7.3 Another JavaScript.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Functions.  Assignment #2 is now due on Wednesday, Nov 25 th  (No Quiz)  Go over the midterm  Backtrack and re-cover the question about tracing the.
CSD 340 (Blum)1 Errors and Debugging and Swapping Variable Values.
CSD 340 (Blum)1 For Loops See Beginning JavaScript (Paul Wilton) p. 87.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
JavaScript Events Java 4 Understanding Events Events add interactivity between the web page and the user You can think of an event as a trigger that.
CSD 340 (Blum)1 Introducing Text Input elements and Ifs.
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
JavaScript 101 Lesson 6: Introduction to Functions.
JavaScript Events. Understanding Events Events add interactivity between the web page and the user Events add interactivity between the web page and the.
1 JavaScript and Dynamic Web Pages Lecture 7. 2 Static vs. Dynamic Pages  A Web page uses HTML tags to identify page content and formatting information.
REEM ALMOTIRI Information Technology Department Majmaah University.
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.
Client-side (JavaScript) Validation. Associating a function with a click event – Part 1 Use the input tag’s onclick attribute to associate a function.
Chapter 6 JavaScript: Introduction to Scripting
Loop Lab CSD 340 (Blum).
JavaScript is a programming language designed for Web pages.
Introduction to Scripting
JavaScript.
Intro to PHP & Variables
WEB PROGRAMMING JavaScript.
We are starting to program with JavaScript
T. Jumana Abu Shmais – AOU - Riyadh
JavaScript What is JavaScript? What can JavaScript do?
JavaScript What is JavaScript? What can JavaScript do?
For this assignment, copy and past the XHTML to a notepad file with the .html extension. Then add the code I ask for to complete the problems.
JavaScript Basics What is JavaScript?
JavaScript: Introduction to Scripting
CIS 136 Building Mobile Apps
Presentation transcript:

CSD 340 (Blum)1 Starting JavaScript Homage to the Homage to the Square

CSD 340 (Blum)2 Homage to the Square This exercise is based on the series of works by Josef Albers entitled “Homage to the Square”

CSD 340 (Blum)3 Use Notepad to enter the HTML code to make a red square using the tag.

CSD 340 (Blum)4 Code Homage to "Homage to the Square" <div style="position: relative; width: 500px; height: 500px; background: #FF0000" ms_positioning="GridLayout">

CSD 340 (Blum)5 Save it and open it in a browser.

CSD 340 (Blum)6 Add another tag within the previous.

CSD 340 (Blum)7 Homage to "Homage to the Square" <div style="position: relative; width: 500px; height: 500px; background: #FF0000" ms_positioning="GridLayout"> <div style="position: absolute; width: 400px; height: 400px; left: 50px; top: 75px; background: #AA5500" ms_positioning="GridLayout">

CSD 340 (Blum)8 Viewed in browser

CSD 340 (Blum)9 Add another (copy and paste comes in handy).

CSD 340 (Blum)10 Viewed in browser.

CSD 340 (Blum)11 Add another (copy and paste comes in handy).

CSD 340 (Blum)12 Viewed in browser.

CSD 340 (Blum)13 Making it interactive Now let us make a version which involves the user by letting him or her select the colors by entering RGB values. An important concept when interfacing with a user is validation – making sure the user has done something sensible within the context of the program. But we have enough to worry about with this exercise, so we will put off validation for another time.

CSD 340 (Blum)14 Add script tags at the bottom but before the (close-body tag).

CSD 340 (Blum)15 New Code alert("Welcome to Homage to Homage to the Square");

CSD 340 (Blum)16 The script tag The tag tells the browser that the text that follows is not HTML but something else. The language attribute informs the browser that the text within is written in JavaScript. The type attribute does the same. The reason for doing it twice is because of possible browser differences. Hopefully the browser will understand one of the versions.

CSD 340 (Blum)17 The alert function The line between the open and closing script tag – alert("Welcome to Homage to Homage to the Square."); is a predefined function that pops up a message window with the given text displayed.

CSD 340 (Blum)18 Viewed in browser.

CSD 340 (Blum)19 Some vocabulary A function is a set of code with some well defined action. In this case, we are just using a function that someone else wrote and that is known to most browsers. Our code is said to call the function (that is, ask that the code be run or executed).

CSD 340 (Blum)20 Some more vocabulary The function has an argument or parameter (in this case the text in the quotes, in the parentheses). An argument allows a function to adapt to different situations; in this case the message window can have different messages. The text in the quotes is called a literal string – we want the message literally to say exactly what we have in the quotes. The term string refers to a set of consecutive characters.

CSD 340 (Blum)21 A problem Suppose we wanted the message window to say Welcome to Homage to “Homage to the Square” that is, to include quotes. The browser would interpret the first quote we want printed as the ending quote of the literal. We can handle this by using an escape sequence – replacing the quotes we want printed by \”.

CSD 340 (Blum)22 Using escape sequence to display quotes.

CSD 340 (Blum)23 Viewed in browser.

CSD 340 (Blum)24 Vocabulary: Delimiter Note that the line of code (known as a statement) ends with a semicolon. The semicolon is known as a delimiter. A delimiter is used to separate one element from another. For example, the English language uses a space as a delimiter between words.

CSD 340 (Blum)25 Add the next three statements.

CSD 340 (Blum)26 User is prompted with message and sample input.

CSD 340 (Blum)27 User might change the sample input and then clicks OK.

CSD 340 (Blum)28 Here we alert the user as to the input he or she has given.

CSD 340 (Blum)29 Variables In the first new statement var FirstColor; we are said to be declaring a variable. If a quantity might change in the execution of the program, we declare a variable to set aside a place (in memory). This allows us to change it but also to hold the value until we have a chance to use it.

CSD 340 (Blum)30 The second new statement FirstColor = prompt("Enter a color in hexadecimal RGB (e.g. #FF0000 is red)","#FF0000"); is a combination of two things. –The first part is the predefined prompt function which has two arguments – the first is a message and the second is a sample input for the user. Both arguments are literal strings. The function brings back (returns) input from a user. –The second part is called an assignment statement (symbolized by the equal sign) that makes the variable on the left-hand side equal to the value obtained from the right-hand side.

CSD 340 (Blum)31 Concatenation The third new statement alert("You have selected " + FirstColor); uses the alert function again. But instead of a simple literal string as an argument, this time the argument is the concatenation of a literal string with a variable having a string value. –Concatenation is a fancy term for having one string follow another.

CSD 340 (Blum)32 Next phase: use the id attribute so we can identify the outermost square (div)

CSD 340 (Blum)33 Write code to change first square’s color based on user’s input.

CSD 340 (Blum)34 The code (note it shoul be on one line, not wrapped as shown below) document.getElementById("FirstSquare"). style.background = FirstColor;

CSD 340 (Blum)35 Viewed in browser (A)

CSD 340 (Blum)36 Viewed in browser (B)

CSD 340 (Blum)37 Viewed in browser (C)

CSD 340 (Blum)38 A comment Note that two slashes can be added to one of the previous statements //alert("You have selected " + FirstColor); This makes the line of text into a comment. A comment is not executed, it has no effect on what the browser displays. It is only seen when one views the source. –It can be used to disable code (as seen here) or to convey information to anyone who might read one’s code. This allows one to document one’s code which is very important.

CSD 340 (Blum)39 Give ids to the other squares.

CSD 340 (Blum)40 Add code that allows the user to change the second color

CSD 340 (Blum)41

CSD 340 (Blum)42

CSD 340 (Blum)43

CSD 340 (Blum)44 Add code for the third and fourth squares.

CSD 340 (Blum)45

CSD 340 (Blum)46

CSD 340 (Blum)47

CSD 340 (Blum)48 References Beginning JavaScript, Paul Wilton Albers, Werner Spies