UID
User Interface Design
23CSE113
User Interface
Design
Prepared by,
Mrs. Sumithra R P
Assistant Professor
Department of CSE
UID
User Interface
JS Functions
Design
Lecture 17
Syllabus
Unit II
CSS Box Model and Positioning - Creating Layouts Using Modern CSS -
Backgrounds and Borders - CSS Transformations and Transitions -
Animating with CSS and the Canvas
Dynamic Web Pages – Web Scripting – JavaScript programming for Web
Applications – Including JavaScript in HTML – HTML5 Form Controls
and Validation - Document Object Model - DOM manipulation and
events - Event Handlers.
3
JavaScript function
A JavaScript function is a block of code designed to
perform a particular task.
A JavaScript function is executed when "something"
invokes it (calls it).
A JavaScript function is defined with the function
keyword, followed by a name, followed by parentheses
().
function name(parameter1, parameter2, parameter3) {
// code to be executed
}
Function
parameters,Arguments
Function parameters are listed inside the parentheses ()
in the function definition.
Function arguments are the values received by the
function when it is invoked.
Inside the function, the arguments (the parameters)
behave as local variables.
Function Invocation
The code inside the function will execute when
"something" invokes (calls) the function:
When an event occurs (when a user clicks a
button)
When it is invoked (called) from JavaScript code
Automatically (self invoked)
Function Return
When JavaScript reaches a return statement,
the function will stop executing.
If the function was invoked from a statement,
JavaScript will "return" to execute the code
after the invoking statement.
Functions often compute a return value. The
return value is "returned" back to the "caller":
Local Variables
Variables declared within a JavaScript function,
become LOCAL to the function.
Local variables can only be accessed from within
the function.
Exercises
Write a function named averageOf4Numbers that receives 4
numbers as parameters and returns the mathematical average
between them.
Write a function named concat3 that receives 3 strings as
parameters (string1, string2, string3) and an additional string
named separator.
Write a function named mostRepetitions that receives 3
parameters:
a string - string1
a string - string2
a letter
and returns the string that has the most occurrences of the
specified letter. If both have the same number of
occurrences return string1.