JavaScript Functions.

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

JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
The Web Warrior Guide to Web Design Technologies
JavaScript Part for Repetition Statement for statement Cpecifies each of the items needed for counter-controlled repetition with a control variable.
 Inside attributes like onclick  As a section of code in the body  Only special cases  As a function in a separate file  Can link to it like the.
Chapter 3 Working with Text and Cascading Style Sheets.
JAVASCRIPT TIPS. REMEMBER JAVASCRIPT IS VERY, VERY CASE SENSITIVE.
JAVASCRIPT HOW TO PROGRAM -2 DR. JOHN P. ABRAHAM UTPA.
Javascript and Basic Programming Concepts. What is a Program? A program is a specific set of instructions written in a computer language to perform a.
CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT
SYST Web Technologies SYST Web Technologies Lesson 6 – Intro to JavaScript.
SERVER web page repository WEB PAGE instructions stores information and instructions BROWSER retrieves web page and follows instructions Server Web Server.
Javascript. Outline Introduction Fundamental of JavaScript Javascript events management DOM and Dynamic HTML (DHTML)
Fluency with Information Technology INFO100 and CSE100 Katherine Deibel Katherine Deibel, Fluency in Information Technology1.
JavaScript - A Web Script Language Fred Durao
David Stotts Computer Science Department UNC Chapel Hill.
SERVER web page repository WEB PAGE instructions stores information and instructions BROWSER retrieves web page and follows instructions Server Web Server.
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
JavaScript Programming Unit #1: Introduction. What is Programming?
Fluency with Information Technology INFO100 and CSE100 Katherine Deibel Katherine Deibel, Fluency in Information Technology1.
JavaScript, Fourth Edition
DYNAMIC HTML What is Dynamic HTML: HTML code that allow you to change/ specify the style of your web pages. Example: specify style sheet, object model.
12/7/2015B.Ramamurthy1 Exam2 Review CSE111 B.Ramamurthy.
Modifying HTML attributes and CSS values. Learning Objectives By the end of this lecture, you should be able to: – Select based on a class (as opposed.
1 JavaScript Part 3. Functions Allow the user to decide when a particular script should be run by the browser in stead of running as long as the page.
CSCE 102 – Chapter 11 (Performing Calculations) CSCE General Applications Programming Benito Mendoza Benito Mendoza 1 By Benito Mendoza.
1/25/2016B.Ramamurthy1 Exam3 Review CSE111 B.Ramamurthy.
Javascript Overview. What is Javascript? May be one of the most popular programming languages ever Runs in the browser, not on the server All modern browsers.
Functions Function is a standalone block of statements that performs some tasks and returns a value. Functions must be declared before they can be used.
JavaScript Functions. CSS Inheritance Which formatting applies? x y z input { display: block; } input.pref { background:red; } If you have a selector.
Understanding JavaScript and Coding Essentials Lesson 8.
JavaScript Introduction and Background. 2 Web languages Three formal languages HTML JavaScript CSS Three different tasks Document description Client-side.
JavaScript and Ajax (JavaScript Functions) Week 5 Web site:
JavaScript- conditions, Math objects. Generic Representation.
 2001 Prentice Hall, Inc. All rights reserved. Outline 1 JavaScript.
 Collection of statements that can be invoked as a unit  Can take parameters  Can be used multiple times  Can call without knowing what they do or.
Precedence Operators Error Types
Week-12 (Lecture-1) Cascading Style Sheets (CSS): describe how documents are presented on screens. Types of Style Sheets: External Style Sheet - Define.
CSS Colors, JavaScript Variables, Conditionals and Basic Methods
Build in Objects In JavaScript, almost "everything" is an object.
Using JavaScript to Show an Alert
>> JavaScript: Location, Functions and Objects
HTML & teh internets.
Loops BIS1523 – Lecture 10.
Variables and Data Types
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
JavaScript functions.
JAVA Script : Functions Ashima Wadhwa
Exam3 Review CSE111 B.Ramamurthy 7/28/2018 B.Ramamurthy.
Programming the Web using XHTML and JavaScript
JavaScript: Functions
JavaScript Functions.
JavaScript Functions.
Web Programming– UFCFB Lecture 17
DHTML Javascript Internet Technology.
Predefined Dialog Boxes
Conditional Branching
More Selections BIS1523 – Lecture 9.
Console.
Javascript: variables and parameters
Event Driven Programming & User Defined Functions
Exam3 Review CSE111 B.Ramamurthy 11/24/2018 B.Ramamurthy.
DHTML Javascript Internet Technology.
Javascript Game Assessment
Reviewing key concepts
Working with Text and Cascading Style Sheets
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.
JavaScript functions.
One Set of Styles Connected to As Many Pages as You Want!!!
Presentation transcript:

JavaScript Functions

What is a function? Collection of statements that can be invoked as a unit Because sometimes we want to do more that a single assignment!

Output Black Box Inputs

Different Types of Functions Who writes? JavaScript provides Someone else writes & you use You write Frist two today

Does function need information? Alert does…tell it what to write Asking for a random number doesn’t Always need to use () Parameters if data needed () if not

Parameters Call a function with a different value every time MUST give it everything that it expects For alert One parameter, the string to print

Return Parameters Function

Statement or part of an expression Alert is a statement; doesn’t give you anything back If you ask for a random number, you expect to get something back

Functions as Statements Performs an action but doesn’t give you anything back Example: alert

Alert String to print Function

But What if I Want a Value Back? For calculator: eval(string) Like alert, takes a string as a parameter Does its magic on the string And gives you back a number You can do what you want with the number Put it in an alert Write it out to a form Do more math on it

Using eval formname.fieldname.value = eval(‘3+5’); alert(eval(formname.inputfield.value));

Format of a Function functionName(parm,parm); Always needs () even if no parameter functionName();

The rules The order of the parameters matter Only a single output 5 - 3 different than 3 -5 Any number of parameters can be defined Fixed for any specific function Only a single output Optional in general But always the same for any specific function More common model

JavaScript Functions

alert Takes an input value (string) Does not return a value

Getting a random number Math.random() Does not need any inputs Returns a value between 0 and 1

Other math functions Take an input value (number) Math.round(num) Math.floor(num) Math.ceil(num) Take an input value (number) Return a value (number)

eval Takes an input value (string) Returns a value (number)

Connecting JavaScript to HTML

Where Do JavaScript Functions Go? Like CSS, can be inline or a separate file Like CSS, an external file is considered better practice Like CSS, link to it from the head section

A Separate JavaScript File <script src="myscripts.js"></script> Myscript.js JavaScript option in komodo will work on it next

FUNCTION: connecting to HTML <head> <script src=“function.js”></script> </head> <body> <button type=“button” onclick=“doit();”> </body> HTML file name function name function doit () { alert(“Hi!”); } JAVASCRIPT (function.js)