JavaScript Loops.

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

Introducing JavaScript
The Web Warrior Guide to Web Design Technologies
Conditional Statements and Loops. Today’s Learning Goals … Learn about conditional statements and their structure Learn about loops and their structure.
CIS101 Introduction to Computing Week 12. Agenda Your questions Solutions to practice text Final HTML/JavaScript Project Copy and paste assignment JavaScript:
Tutorial 10 Programming with JavaScript
CIS101 Introduction to Computing Week 11. Agenda Your questions Copy and Paste Assignment Practice Test JavaScript: Functions and Selection Lesson 06,
XP Tutorial 1 New Perspectives on JavaScript, Comprehensive1 Introducing JavaScript Hiding Addresses from Spammers.
2012 •••••••••••••••••••••••••••••••••• Summer WorkShop Mostafa Badr
Introduction to JavaScript. Aim To enable you to write you first JavaScript.
Programming Concepts MIT - AITI. Variables l A variable is a name associated with a piece of data l Variables allow you to store and manipulate data in.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
What is Java Script? An extension to HTML. An extension to HTML. Allows authors to incorporate some functionality in their web pages. (without using CGI.
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
1 JavaScript in Context. Server-Side Programming.
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 2: What is JavaScript?
Tutorial 10 Programming with JavaScript. XP Objectives Learn the history of JavaScript Create a script element Understand basic JavaScript syntax Write.
Introduction.  The scripting language most often used for client-side web development.  Influenced by many programming languages, easier for nonprogrammers.
JavaScript Adding active content to websites. Goals Understand structure of JavaScript Understand rules of coding Add active content to WebPages Add functions.
7 1 User-Defined Functions CGI/Perl Programming By Diane Zak.
Overview of Form and Javascript fundamentals. Brief matching exercise 1. This is the software that allows a user to access and view HTML documents 2.
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.
1 Server versus Client-Side Programming Server-SideClient-Side.
1 JavaScript in Context. Server-Side Programming.
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.
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.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
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.
Learning Javascript From Mr Saem
JavaScript and AJAX 2nd Edition Tutorial 1 Programming with JavaScript.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
PHP using MySQL Database for Web Development (part II)
Java Script Introduction. Java Script Introduction.
Chapter 6 JavaScript: Introduction to Scripting
JavaScript Wrap-up.
JavaScript - Errors & Exceptions Handling
JAVA Script : Functions Ashima Wadhwa
* Lecture # 7 Instructor: Rida Noor Department of Computer Science
Variables, Expressions, and IO
Introduction to Scripting
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
JavaScript Part 2 Organizing JavaScript Code into Functions
JavaScript.
Your 1st Programming Assignment
INFO/CSE 100, Spring 2005 Fluency in Information Technology
The Web Wizard’s Guide To JavaScript
PHP.
T. Jumana Abu Shmais – AOU - Riyadh
Algorithms Take a look at the worksheet. What do we already know, and what will we have to learn in this term?
CS105 Introduction to Computer Concepts
Tutorial 10 Programming with JavaScript
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 6 Test Javascript Test.
Tutorial 10: Programming with javascript
BIT116: Scripting Lecture 6 Part 1
Introduction to Programming and JavaScript
Repetition Statements (Loops) - 2
Web Programming– UFCFB Lecture 13
CIS 136 Building Mobile Apps
CS105 Introduction to Computer Concepts JavaScript
JavaScript 101 Lesson 8: Loops.
How to allow the program to know when to stop a loop.
Presentation transcript:

JavaScript Loops

Loops A loop is a block of code that allows you to repeat a section of code a certain number of times, perhaps changing certain variable values each time the code is executed.

Why loops are useful? Loops are useful because they allow you to repeat lines of code without retyping them or using cut and paste in your text editor. They save time and trouble of repeatedly typing the same lines of code, but also avoids typing errors in repeated lines. You are also able to change one or more variable values each time the browser passes through the loop.

For loop for ( varname=1;varname<11;varname+=1 ) initialization Tells the loops when to stop running Determines the rate at which the variable is changed and whether it gets larger or smaller

While loop A while loop just looks at a short comparison and repeats until the comparison is no longer true. while(varname<11) { }

1. This is loop 1 2. This is loop 2 3. This is loop 3 4 1. This is loop 1 2. This is loop 2 3. This is loop 3 4. This is loop 4 5. Break the loop ! 6. This is loop 6 7. This is loop 7 8. This is loop 8 9. This is loop 9 10. This is loop 10 Note: “IF”

Functions

User-defined function Is a JavaScript code that is written to perform certain tasks repeatedly User-defined function Is one which the Web developer writes the tasks to be performed

Why functions are useful? Helps organize various parts of a script into the difference tasks that must be accomplished Functions are portable. Functions are time-saving.

Defining the code for functions

Naming functions Function names are case sensitive Function name must begin with a letter or an underscore character Function name cannot contain any spaces Avoid reserved words Give functions memorable and meaningful names

Calling functions in your scripts A call to a function in JavaScript is simply the function name along with the set of parentheses, ending with a semicolon, like a normal JavaScript statement. functionname( )

<html> <head> </head> <body> <script type="text/javascript"> function display_alert() { alert("") } display_alert() </script> </body> </html>

<html> <head> <script type="text/javascript"> function myfunction() { alert(“This is an alert box"); } </script> </head> <body> <form> <input type="button" onclick="myfunction()" value="Call function"> </form> </body> </html>

Save your files here \\pshs-storage\CS3WEB\2nd Quarter\Magnesium_Functions\lastname_lastname.html