Computer Science 103 Chapter 3 Introduction to JavaScript.

Slides:



Advertisements
Similar presentations
1 What is JavaScript? JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting language A scripting language is a lightweight.
Advertisements

Java Script Session1 INTRODUCTION.
The Web Warrior Guide to Web Design Technologies
14/11/11.  These words have special meanings in themselves  These should NOT be used as Identifiers.  For example:  Break, do, function, case, else,
1 Javascrbipt Intro Javascript (or js) is a programming language. Interpreted, not compiled. Not the same as java, but, similar. Use tags to use. Object-oriented.
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.
Tutorial 10 Programming with JavaScript
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 JavaScript for Python Programmers
Introduction to scripting
Javascript and the Web Whys and Hows of Javascript.
WEB DESIGN AND PROGRAMMING Introduction to Javascript.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
Bridges To Computing General Information: This document was created for use in the "Bridges to Computing" project of Brooklyn College. You are invited.
Week 9 PHP Cookies and Session Introduction to JavaScript.
Javascript. Outline Introduction Fundamental of JavaScript Javascript events management DOM and Dynamic HTML (DHTML)
Chapter 4 JavaScript and Dynamic Web pages. Objectives Static Web pages Dynamic Web pages JavaScript Variables Assignments. JavaScript Functions –(prompt(“”,””)
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?
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
20-753: Fundamentals of Web Programming 1 Lecture 12: Javascript I Fundamentals of Web Programming Lecture 12: Introduction to Javascript.
7 1 User-Defined Functions CGI/Perl Programming By Diane Zak.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
1 JavaScript
Input & Output Functions JavaScript is special from other languages because it can accept input and produce output on the basis of that input in the same.
JavaScript Syntax, how to use it in a HTML document
JavaScript - Basic Concepts Prepared and Presented by Hienvinh Nguyen, Afshin Tiraie.
 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.
JavaScript, Fourth Edition
COMP403 Web Design JAVA SCRİPTS Tolgay KARANFİLLER.
1 Chapter 3 – JavaScript Outline Introduction Flowcharts Control Structures if Selection Structure if/else Selection Structure while Repetition Structure.
Introduction into JavaScript Java 1 JavaScript JavaScript programs run from within an HTML document The statements that make up a program in an HTML.
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.
Making dynamic pages with javascript Lecture 1. Java script java versus javascript Javascript is a scripting language that will allow you to add real.
CIS 375—Web App Dev II JavaScript I. 2 Introduction to DTD JavaScript is a scripting language developed by ________. A scripting language is a lightweight.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
Creating Web Documents: JavaScript Ftp / file management: review Introduction to JavaScript Sources Homework: start review for midterm, work on Project.
Introduction to JavaScript CSc 2320 Fall 2014 Disclaimer: All words, pictures are adopted from “Simple JavaScript”by Kevin Yank and Cameron Adams and also.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
Tutorial 11 1 JavaScript Operators and Expressions.
Chapter 5: Intro to Scripting CIS 275—Web Application Development for Business I.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
Introduction to Javascript. What is javascript?  The most popular web scripting language in the world  Used to produce rich thin client web applications.
JavaScript 101 Lesson 6: Introduction to Functions.
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.
 2001 Prentice Hall, Inc. All rights reserved. Outline 1 JavaScript.
© 2010 Robert K. Moniot1 Chapter 6 Introduction to JavaScript.
>> Introduction to JavaScript
Chapter 6 JavaScript: Introduction to Scripting
WEB APPLICATION PROGRAMMING
JavaScript.
CHAPTER 4 CLIENT SIDE SCRIPTING PART 2 OF 3
INFO/CSE 100, Spring 2005 Fluency in Information Technology
The Web Wizard’s Guide To JavaScript
T. Jumana Abu Shmais – AOU - Riyadh
JavaScript What is JavaScript? What can JavaScript do?
INFO/CSE 100, Spring 2006 Fluency in Information Technology
CS105 Introduction to Computer Concepts
JavaScript What is JavaScript? What can JavaScript do?
Tutorial 10: Programming with javascript
JavaScript: Introduction to Scripting
CIS 136 Building Mobile Apps
Web Programming and Design
CS105 Introduction to Computer Concepts JavaScript
Presentation transcript:

Computer Science 103 Chapter 3 Introduction to JavaScript

JavaScript What is it? Comments, Print text Variables assignments & expressions Control Structures Functions & external JavaScript files

What is JavaScript? JavaScript is a scripting language that allows web pages added flexibility and functionality. It is not HTML, though it works with HTML. – HTML pages are static, JavaScript can be dynamic. – JavaScript is a programming language, HTML is not.

What is JavaScript Cont ’ d JavaScript code is enclosed in All JavaScript code must be in between these tags.

Comments & Printing text Comments are code that is not printed in the browser, they are only viewable in the source. JavaScript comments, different than HTML: – // line comments – /* block comment line 2*/ Comments are useful: – Explain your code to other programmers – Help you remember what your code does

Comments & Printing text document.write() – Writes a line to the webpage. – document.write("Hello World!"); document.writeln() – Writes a line to the page with a carriage return at the end. – Must be between … tags – document.writeln("Hello World");

Variables Assignments A variable is a place to store a value. Three types of variables – Number (12543) – Logical/Boolean (TRUE/FALSE) – String ("HELLO") To assign a value to a variable use “ = “ – x = 42 y = false

Expressions An expression is a statement that JavaScript can evaluate to produce a value. – z = x + y (Numeric) Adds x & y – z = x + y (String) Concatenates text x and text y together Concatenates "box" + "check" is equal to "checkbox" z = "hello" + "world" is equal to "helloworld" – Standard -, *, / can also be used for numbers

Expressions A simple example with integers myNumber = 10; theAnswer = (myNumber + 5) / 5; document.writeln( " The answer is: " + theAnswer); A simple example with text myFirstName = "Joe"; myLastName = "Schmoe"; document.writeln(myFirstName + " " + myLastName);

Control Structures IF ….Then statement – The word if. – A conditional expression enclosed by parentheses. – Executable statements following the conditional expression. Example if (5 > 4){ document.writeln("You are correct!"); }

Control Structures If ….another example var number = 5; if(number == 4){ //this line will not print document.writeln("Number = 4"); } else{ //this line will print document.writeln("Number = " + number); }

Control Structures While statement – First checks if a conditional statement is true – If true, it loops through a set of executable statements until the conditional statement becomes false. Example var x = 4; while(x > 2){ document.writeln("x = " + x); x--; }

Functions Function – A reusable code-block that will be executed by an event, or when the function is called. – Should be defined in HEAD section for better organization – alert(), confirm(), and prompt() are built-in functions – It is very useful to make your own functions to perform repeated tasks

Example that requires two parameters function max(num1, num2){ if(num1 > num2) return num1; else return num2; } Functions

Example of how to call the function max x = 5; y = 6; z = max(x, y); document.writeln("The largest number was equal to " + z); Functions

Including External files – Useful for calling frequently used JavaScript on many pages – The external file only contain JavaScript code – Could be used to include the Honor Code on every page Example //other JavaScript goes here External.js files