Simple Javascript Example

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

In our lesson today we will learn how to find the area of a building.
Javascript Document Object Model. How to use JavaScript  JavaScript can be embedded into your html pages in a couple of ways  in elements in both and.
CS 142 Lecture Notes: RubySlide 1 Basic Ruby Syntax sum = 0 i = 1 while i
CS 142 Lecture Notes: JavascriptSlide 1 Simple Javascript Example sum = 0; for (i = 1; i < 10; i++) { sum += i*i; }
AngularJS Controllers. A controller is a JavaScript object, created by a standard JavaScript object constructor. ng-controller directive defines an application.
1 CS101 Introduction to Computing Lecture 35 Mathematical Methods (Web Development Lecture 12)
1 CS101 Introduction to Computing Lecture 32 Event Handling (Web Development Lecture 11)
Web Programming and Security Lecture 1 Tamara Rezk.
Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
DHTML: Dynamic HTML Internet Technology1. What is DHTML? A collection of enhancements to HTML ► To create dynamic and interactive websites Combination.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
Lab 3: Actionscript User Interface Lab: GUI Lab Sep. 11 th, 2012.
This is the series In other words it is Consider the bars and how the represent the numbers in the sequence, and how the total sum of all.
Scripts Chapter Scripts Small programs used to add interactivity to your web pages The backbone of Dynamic HTML (DHTML) Most scripts are written.
Introduction to Client Side Scripting CS Client Side Scripting Client side means the Browser is interpreting the script Script is downloaded with.
JS Basics 1 Lecture JavaScript - Basics. JS Basics 2 What is JavaScript JavaScript is a “simple”, interpreted, programming language with elementary object-
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.
1 JavaScript Functions and Objects. 2 Objectives You will be able to Use JavaScript functions in JavaScript scripts. Get JavaScript functions executed.
JQuery Introduction © Copyright 2014, Fred McClurg All Rights Reserved.
Introduction to Programming and JavaScript. Programming.
Web Programming Java Script & jQuery Web Programming.
“The world’s most misunderstood language has become the world’s most popular programming language” Akshay Arora
Lecture Exercise (Wk4) CS1301 Introduction To Computer Programming (11-12 Semester B) Page 1 Question 2 (a)Complete the code.
CS 142 Lecture Notes: JavascriptSlide 1 Simple Javascript Example sum = 0; for (i = 1; i < 10; i++) { sum += i*i; }
CS 142 Lecture Notes: JavascriptSlide 1 Simple Javascript Example sum = 0; for (i = 1; i < 10; i++) { sum += i*i; }
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
JAVASCRIPT A quick review. True False ■The DOM is a standardized way of referring to parts of a Web page. ■TRUE ■In the DOM, attributes have their own.
Internet & World Wide Web How to Program, 5/e.  JavaScript events  allow scripts to respond to user interactions and modify the page accordingly  Events.
Build in Objects In JavaScript, almost "everything" is an object.
Classes and Class Members
© 2016, Mike Murach & Associates, Inc.
Area of a Triangle.
Using JavaScript to Show an Alert
>> JavaScript: Location, Functions and Objects
Classes and Class Members
HTML & teh internets.
ATLAS WEB JavaScript & the DOM.
JavaScript Event Handling.
Intro to JavaScript CS 1150 Spring 2017.
CS 330 Class 5 Programming plan for today: Questions on homework
Geometric Model for Distributive Property
Inheritance and Prototypes
JavaScript Client-side
JavaScript.
14 A Brief Look at JavaScript and jQuery.
The Web Wizard’s Guide To DHTML and CSS
Google Maps: A Short How-to
JavaScript Events.
Basic Ruby Syntax sum = 0 i = 1 while i <= 10 do sum += i*i
CS 142 Lecture Notes: Events
DHTML Javascript Internet Technology.
CS 142 Lecture Notes: Events
Substitution in string value
DHTML Javascript Internet Technology.
The Internet 12/8/11 JavaScript Review
Implementing Non-Static Features
The Web Wizard’s Guide To JavaScript
Simple Javascript Example
with a value of javascript:onclick=resizeWindow()
Extend Text Editor to Draw shapes
The Web Wizard’s Guide To JavaScript
Simple Javascript Example
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.
Unit 6 part 5 Test Javascript Test.
Tutorial 10: Programming with javascript
Introduction to Programming and JavaScript
The <script> Tag
CNIT 133 Interactive Web Pags – JavaScript and AJAX
Basic Ruby Syntax sum = 0 i = 1 while i <= 10 do sum += i*i
Presentation transcript:

Simple Javascript Example sum = 0; for (i = 1; i < 10; i++) { sum += i*i; } CS 142 Lecture Notes: Javascript

Factorial in Javascript function fac(x) { if (x <= 1) { return 1; } return x*fac(x-1); CS 142 Lecture Notes: Javascript

CS 142 Lecture Notes: Javascript Method Example o = new Object(); o.count = 0; o.increment = function(inc) { if (inc == undefined) { inc = 1; } this.count += inc; return this.count; CS 142 Lecture Notes: Javascript

Functions Can Have Properties function plus1(value) { if (plus1.invocations == undefined) { plus1.invocations = 0; } plus1.invocations++; return value+1; CS 142 Lecture Notes: Javascript

CS 142 Lecture Notes: Javascript Constructor function Rectangle(width, height) { this.width = width; this.height = height; } r = new Rectangle(26, 14); CS 142 Lecture Notes: Javascript

Methods (the wrong way) function Rectangle(width, height) { this.width = width; this.height = height; this.area = function() { return this.width*this.height; } r = new Rectangle(26, 14); a = r.area(); CS 142 Lecture Notes: Javascript

CS 142 Lecture Notes: Javascript Prototypes function Rectangle(width, height) { this.width = width; this.height = height; } Rectangle.prototype.area = function() { return this.width*this.height; r = new Rectangle(26, 14); a = r.area(); CS 142 Lecture Notes: Javascript

Embedding Javascript External Javascript File Inline Code <body> ... <script type="text/javascript" src="myCode.js" /> <script type="text/javascript"> //<![CDATA[ alert("Page is loading"); //]]> </script> <p onclick="alert(Hello, world!');"> Click here.</p> </body> Inline Code Event Handler CS 142 Lecture Notes: Javascript

CS 142 Lecture Notes: Cookies