It - Unit 3
It - Unit 3
Elements of Web Design: There are basically two elements of web design i.e., visual
elements and functional elements.
1. Visual Elements:
Visual elements simply mean an aspect or representation of something that we see. There are
various visual elements and some of them are given below:
• Layout: Layout simply represents the overall structure of the website that includes
graphics, ads, texts, headers, menus, content, etc. The website layout is very important as it
helps to guide users and tell them where they want to look. A good layout will also make it
easy for one to have access to information and give a clear path for navigation. There are
different layouts available nowadays and one can choose any one of them as there are no
such rules when choosing a layout.
• Shapes: Shapes simply mark the boundaries of content. It also plays important role in
branding. Each geometrical or graphical shape has its own meaning that influences our
mind. Shapes simply represent a concept, create movement, affect the composition, help to
create complex drawings and paintings, provide depth and texture, etc. It also helps to
increase the number of visitors on the website as appearance influence peoples that in turn
improve your business.
• Colors: Choosing appropriate colors for web design is very essential and important. It can
be considered a powerful element in developing a website successfully. It is a way to
connect to users or visitors and increase brand recognition. Effective usage of color attracts
people and increases the number of visitors. One can choose different colors as per their
choice.
• Images and Icons: Images and icons are the best way to improve the user experience of
your website as well as attract the attention of users. It is the best and most compatible way
to present information and explaining concepts. It makes the website look professional and
more interesting. It also supports text content and gives a quick summary of the text.
2. Functional Elements:
Functional elements simply mean aspect or rep0resentation of functionalities of websites. It
simply represents what the website can do and how it works. There are various functional
elements and some of them are given below:
• Navigation: Navigation simply means the process of monitoring and controlling the
movement around websites or screens, etc. It simply directs visitors or users to various web
pages and will allow searching websites for longer. It is one of the best ways to determine
whether the website is working properly or not.
• User Interaction: The user interface is very important as it will either make and increase
visitors to your website or break the user base. It simply attracts users and simplifies their
activities. It is basically a point where users interact with websites such as scrolling,
clicking, typing, etc.
• Animation: Animations play a very important role to attract more users and enhance the
user experience. Animation simply demonstrates a product or images and are mostly made
with CGI (Computer Generated Imagery). It allows one to do more with less, interacts with
people in a better way, and communicate clearly and effectively.
Client-side scripting : Client-side scripting is a technique that allows a browser to run scripts
without connecting to a server, usually on the user's device. It's a way to enhance the
interactivity of websites and online pages, and is often used on the front end where the user can
see what's happening through their browser.
Client-side scripting can be used for a variety of purposes, including:
• User event functionality: For example, running scripts when a form loads, after it's submitted,
or when a field changes value
• Data processing: For example, getting data from a user's screen or browser
• Data validation
• Creating cookies
Client-side scripting is historically associated with HTML, but JavaScript is now the most
popular language for it because it's universally compatible across browsers and platforms. Other
scripting languages can also be used if the user's browser supports them.
Client-side scripting simply means running scripts, such as JavaScript, on the client device,
usually within a browser.
Server-side scripting
Server-side scripting is a web development technique that uses scripts on a web server to
generate dynamic content for each user's request. These scripts can communicate with databases
and other resources to produce HTML, CSS, and JavaScript code that can be displayed in a
user's browser.
Server-side scripting can be used to create dynamic web pages that can be customized based on
user input or other data. It can also allow for secure authentication and access to
databases. Server-side scripting can have several advantages, including:
• Faster loading times
• Improved Google rating
• Fewer users abandoning the site due to slow loading times
• Avoids issues like freezing, high CPU consumption, and slow loading
Server-side scripts can be written in a variety of languages that the server supports, including
JavaScript.
Difference between client-side scripting and server-side scripting :
Client-side scripting Server-side scripting
Its main function is to provide the Its primary function is to manipulate and provide
requested output to the end user. access to the respective database as per the request.
It does not provide security for data. It provides more security for data.
HTML, CSS, and javascript are used. PHP, Python, Java, Ruby are used.
No need of interaction with the server. It is all about interacting with the servers.
Client-side scripting Server-side scripting
• Model
Defines the data and business logic the app should contain. For example, a shopping list app
might specify the data for each item, including its name and price.
• View
Defines how the app's data should be displayed. For example, a shopping list app might define
how the list is presented to the user.
• Controller
Contains logic that updates the model and/or view in response to input from the users of the
app. For example, a shopping list app might have input forms and buttons that allow users to
add or delete items. In web applications, controllers also handle HTTP requests and
responses.
• Note: Some HTML elements have no content (like the <br> element). These elements are
called empty elements. Empty elements do not have an end tag!
Web Browsers
The purpose of a web browser (Chrome, Edge, Firefox, Safari) is to read HTML documents and
display them correctly.
A browser does not display the HTML tags, but uses them to determine how to display the
document:
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "Paragraph changed.";
}
</script>
</body>
</html>
Placing scripts at the bottom of the <body> element improves the display speed, because script
interpretation slows down the display.
External JavaScript
Scripts can also be placed in external files:
External file: myScript.js
function myFunction() {
document.getElementById("demo").innerHTML = "Paragraph changed.";
}
External scripts are practical when the same code is used in many different web pages.
JavaScript files have the file extension .js.
To use an external script, put the name of the script file in the src (source) attribute of
a <script> tag:
Example
<script src="myScript.js"></script>
You can place an external script reference in <head> or <body> as you like.
The script will behave as if it was located exactly where the <script> tag is located.
External scripts cannot contain <script> tags.
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = 5 + 6;
</script>
</body>
</html>
Changing the innerHTML property of an HTML element is a common way to display
data in HTML. Using document.write()
For testing purposes, it is convenient to use document.write():
Example
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Using document.write() after an HTML document is loaded, will delete all existing HTML:
Example
<!DOCTYPE html>
<html>
<body>
</body>
</html>
<script>
window.alert(5 + 6);
</script>
</body>
</html>
JavaScript Print
JavaScript does not have any print object or print methods.
You cannot access output devices from JavaScript.
The only exception is that you can call the window.print() method in the browser to print the
content of the current window.
Example
<!DOCTYPE html>
<html>
<body>
</body>
</html>
JavaScript Statements
JavaScript statements are composed of:
Values, Operators, Expressions, Keywords, and Comments.
This statement tells the browser to write "Hello Dolly." inside an HTML element with
id="demo":
Example
document.getElementById("demo").innerHTML = "Hello Dolly.";
Most JavaScript programs contain many JavaScript statements.
The statements are executed, one by one, in the same order as they are written.
JavaScript programs (and JavaScript statements) are often called JavaScript code.
Semicolons ;
Semicolons separate JavaScript statements.
Add a semicolon at the end of each executable statement:
Examples
let a, b, c; // Declare 3 variables
a = 5; // Assign the value 5 to a
b = 6; // Assign the value 6 to b
c = a + b; // Assign the sum of a and b to c
When separated by semicolons, multiple statements on one line are allowed:
a = 5; b = 6; c = a + b;
JavaScript White Space
JavaScript ignores multiple spaces. You can add white space to your script to make it more
readable.
The following lines are equivalent:
let person = "Hege";
let person="Hege";
A good practice is to put spaces around operators ( = + - * / ):
let x = y + z;
JavaScript Line Length and Line Breaks
For best readability, programmers often like to avoid code lines longer than 80 characters.
If a JavaScript statement does not fit on one line, the best place to break it is after an operator:
Example
document.getElementById("demo").innerHTML =
"Hello Dolly!";
JavaScript Code Blocks
JavaScript statements can be grouped together in code blocks, inside curly brackets {...}.
The purpose of code blocks is to define statements to be executed together.
One place you will find statements grouped together in blocks, is in JavaScript functions:
Example
function myFunction() {
document.getElementById("demo1").innerHTML = "Hello Dolly!";
document.getElementById("demo2").innerHTML = "How are you?";
}
JavaScript statements often start with a keyword to identify the JavaScript action to be
performed.
Keyword Description
var Declares a variable
let Declares a block variable
const Declares a block constant
if Marks a block of statements to be executed on a condition
switch Marks a block of statements to be executed in different cases
for Marks a block of statements to be executed in a loop
function Declares a function
return Exits a function
try Implements error handling to a block of statements
JavaScript Syntax
JavaScript syntax is the set of rules, how JavaScript programs are constructed:
// How to create variables:
var x;
let y;
JavaScript Values
The JavaScript syntax defines two types of values:
• Fixed values
• Variable values
Fixed values are called Literals.
Variable values are called Variables.
JavaScript Literals
The two most important syntax rules for fixed values are:
1. Numbers are written with or without decimals:
10.50
1001
2. Strings are text, written within double or single quotes:
"John Doe"
'John Doe'
JavaScript Variables
In a programming language, variables are used to store data values.
JavaScript uses the keywords var, let and const to declare variables.
An equal sign is used to assign values to variables.
In this example, x is defined as a variable. Then, x is assigned (given) the value 6:
let x;
x = 6;
JavaScript Operators
JavaScript uses arithmetic operators ( + - * / ) to compute values:
(5 + 6) * 10
JavaScript uses an assignment operator ( = ) to assign values to variables:
let x, y;
x = 5;
y = 6;
JavaScript Expressions
An expression is a combination of values, variables, and operators, which computes to a value.
The computation is called an evaluation.
For example, 5 * 10 evaluates to 50:
5 * 10
Expressions can also contain variable values:
x * 10
The values can be of various types, such as numbers and strings.
For example, "John" + " " + "Doe", evaluates to "John Doe":
"John" + " " + "Doe"
JavaScript Keywords
JavaScript keywords are used to identify actions to be performed.
The let keyword tells the browser to create variables:
let x, y;
x = 5 + 6;
y = x * 10;
The var keyword also tells the browser to create variables:
var x, y;
x = 5 + 6;
y = x * 10;
In these examples, using var or let will produce the same result.
You will learn more about var and let later in this tutorial.
JavaScript Comments
Not all JavaScript statements are "executed".
Code after double slashes // or between /* and */ is treated as a comment.
Comments are ignored, and will not be executed:
In these examples, using var or let will produce the same result.
You will learn more about var and let later in this tutorial.
JavaScript Comments
Not all JavaScript statements are "executed".
Code after double slashes // or between /* and */ is treated as a comment.
Comments are ignored, and will not be executed:
let x = 5; // I will be executed
// Without decimals:
let x2 = 34;
Exponential Notation
Extra large or extra small numbers can be written with scientific (exponential) notation:
Example
let y = 123e5; // 12300000
let z = 123e-5; // 0.00123
JavaScript Booleans
Booleans can only have two values: true or false.
Example
let x = 5;
let y = 5;
let z = 6;
(x == y) // Returns true
(x == z) // Returns false
JavaScript Arrays
JavaScript arrays are written with square brackets.
Array items are separated by commas.
The following code declares (creates) an array called cars, containing three items (car names):
Example
const cars = ["Saab", "Volvo", "BMW"];
Array indexes are zero-based, which means the first item is [0], second is [1], and so on.
JavaScript Objects
JavaScript objects are written with curly braces {}.
Object properties are written as name:value pairs, separated by commas.
Example
const person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};
The typeof Operator
You can use the JavaScript typeof operator to find the type of a JavaScript variable.
The typeof operator returns the type of a variable or an expression:
Example
typeof "" // Returns "string"
typeof "John" // Returns "string"
typeof "John Doe" // Returns "string"
Undefined
In JavaScript, a variable without a value, has the value undefined. The type is also undefined.
Example
let car; // Value is undefined, type is undefined
Any variable can be emptied, by setting the value to undefined. The type will also
be undefined.
Empty Values
An empty value has nothing to do with undefined.
An empty string has both a legal value and a type.
Example
let car = ""; // The value is "", the typeof is "string"
JavaScript Operators
Javascript operators are used to perform different types of mathematical and logical
computations.
Examples:
The Assignment Operator = assigns values
The Addition Operator + adds values
The Multiplication Operator * multiplies values
The Comparison Operator > compares values
JavaScript Assignment
The Assignment Operator (=) assigns a value to a variable:
Assignment Examples
let x = 10;
// Assign the value 5 to x
let x = 5;
// Assign the value 2 to y
let y = 2;
// Assign the value x + y to z:
let z = x + y;
JavaScript Addition
The Addition Operator (+) adds numbers:
Adding
let x = 5;
let y = 2;
let z = x + y;
JavaScript Multiplication
The Multiplication Operator (*) multiplies numbers:
Multiplying
let x = 5;
let y = 2;
let z = x * y;
Types of JavaScript Operators
There are different types of JavaScript operators:
• Arithmetic Operators
• Assignment Operators
• Comparison Operators
• String Operators
• Logical Operators
• Bitwise Operators
• Ternary Operators
• Type Operators
JavaScript Arithmetic Operators
Arithmetic Operators are used to perform arithmetic on numbers:
Arithmetic Operators Example
let a = 3;
let x = (100 + 50) * a;
Operator Description
+ Addition
- Subtraction
* Multiplication
** Exponentiation (ES2016)
/ Division
% Modulus (Division Remainder)
++ Increment
-- Decrement
JavaScript Assignment Operators
Assignment operators assign values to JavaScript variables.
The Addition Assignment Operator (+=) adds a value to a variable.
Assignment
let x = 10;
x += 5;
Operator Example Same As
= x=y x=y
+= x += y x=x+y
-= x -= y x=x-y
*= x *= y x=x*y
/= x /= y x=x/y
%= x %= y x=x%y
**= x **= y x = x ** y
JavaScript Comparison Operators
Operator Description
== equal to
=== equal value and equal type
!= not equal
!== not equal value or not equal type
> greater than
< less than
>= greater than or equal to
<= less than or equal to
? ternary operator
JavaScript Functions
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).
Example
// Function to compute the product of p1 and p2
function myFunction(p1, p2) {
return p1 * p2;
}
JavaScript Function Syntax
A JavaScript function is defined with the function keyword, followed by a name, followed by
parentheses ().
Function names can contain letters, digits, underscores, and dollar signs (same rules as
variables).
The parentheses may include parameter names separated by commas:
(parameter1, parameter2, ...)
The code to be executed, by the function, is placed inside curly brackets: {}
function name(parameter1, parameter2, parameter3) {
// code to be executed
}
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":
Example
Calculate the product of two numbers, and return the result:
// Function is called, the return value will end up in x
let x = myFunction(4, 3);
function myFunction(a, b) {
// Function returns the product of a and b
return a * b;
}
Why Functions?
With functions you can reuse code
You can write code that can be used many times.
You can use the same code with different arguments, to produce different results.
The () Operator
The () operator invokes (calls) the function:
Example
Convert Fahrenheit to Celsius:
function toCelsius(fahrenheit) {
return (5/9) * (fahrenheit-32);
}
function myFunction() {
let carName = "Volvo";
// code here CAN use carName
}
Creating an Array
Using an array literal is the easiest way to create a JavaScript Array.
Syntax:
const array_name = [item1, item2, ...];
Conditional Statements
Very often when you write code, you want to perform different actions for different decisions.
You can use conditional statements in your code to do this.
In JavaScript we have the following conditional statements:
• Use if to specify a block of code to be executed, if a specified condition is true
• Use else to specify a block of code to be executed, if the same condition is false
• Use else if to specify a new condition to test, if the first condition is false
• Use switch to specify many alternative blocks of code to be executed
The if Statement
Use the if statement to specify a block of JavaScript code to be executed if a condition is true.
Syntax
if (condition) {
// block of code to be executed if the condition is true
}
Note that if is in lowercase letters. Uppercase letters (If or IF) will generate a JavaScript error.
Example
Make a "Good day" greeting if the hour is less than 18:00:
if (hour < 18) {
greeting = "Good day";
}
The else Statement
Use the else statement to specify a block of code to be executed if the condition is false.
if (condition) {
// block of code to be executed if the condition is true
} else {
// block of code to be executed if the condition is false
}
Example
If the hour is less than 18, create a "Good day" greeting, otherwise "Good evening":
if (hour < 18) {
greeting = "Good day";
} else {
greeting = "Good evening";
}
The result of greeting will be:
Good evening
The else if Statement
Use the else if statement to specify a new condition if the first condition is false.
Syntax
if (condition1) {
// block of code to be executed if condition1 is true
} else if (condition2) {
// block of code to be executed if the condition1 is false and condition2 is true
} else {
// block of code to be executed if the condition1 is false and condition2 is false
}
Example
If time is less than 10:00, create a "Good morning" greeting, if not, but time is less than 20:00,
create a "Good day" greeting, otherwise a "Good evening":
if (time < 10) {
greeting = "Good morning";
} else if (time < 20) {
greeting = "Good day";
} else {
greeting = "Good evening";
}
The result of greeting will be:
Good evening
JavaScript Switch Statement
The switch statement is used to perform different actions based on different conditions.
Strict Comparison
Switch cases use strict comparison (===).
The values must be of the same type to match.
A strict comparison can only be true if the operands are of the same type.
In this example there will be no match for x:
Example
let x = "0";
switch (x) {
case 0:
text = "Off";
break;
case 1:
text = "On";
break;
default:
text = "No value found";
}
JavaScript For Loop
Different Kinds of Loops
JavaScript supports different kinds of loops:
• for - loops through a block of code a number of times
• for/in - loops through the properties of an object
• for/of - loops through the values of an iterable object
• while - loops through a block of code while a specified condition is true
• do/while - also loops through a block of code while a specified condition is true
Loop Scope
Using var in a loop:
Example
var i = 5;
// Here i is 10
JavaScript For In
The For In Loop
The JavaScript for in statement loops through the properties of an Object:
Syntax
for (key in object) {
// code block to be executed
}
Example
const person = {fname:"John", lname:"Doe", age:25};
function myFunction(value) {
txt += value;
}
JavaScript While Loop
Loops can execute a block of code as long as a specified condition is true.
for (;cars[i];) {
text += cars[i];
i++;
}
The loop in this example uses a while loop to collect the car names from the cars array:
Example
const cars = ["BMW", "Volvo", "Saab", "Ford"];
let i = 0;
let text = "";
while (cars[i]) {
text += cars[i];
i++;
}
JavaScript Break and Continue
The break statement "jumps out" of a loop.
The continue statement "jumps over" one iteration in the loop.
continue labelname;
The continue statement (with or without a label reference) can only be used to skip one loop
iteration.
The break statement, without a label reference, can only be used to jump out of a loop or a
switch.
With a label reference, the break statement can be used to jump out of any code block:
Example
const cars = ["BMW", "Volvo", "Saab", "Ford"];
list: {
text += cars[0] + "<br>";
text += cars[1] + "<br>";
break list;
text += cars[2] + "<br>";
text += cars[3] + "<br>";
}
A code block is a block of code between { and }.
Bootstrap: Bootstrap is a free and open-source tool collection used to create responsive websites and web applications. It is
the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites. Nowadays, websites
created using Bootstrap are compatible with all browsers (IE, Firefox, and Chrome) and with all screen sizes (Desktops, Tablets,
Phablets, and Phones). Bootstrap was initially developed by Mark Otto and Jacob Thornton of Twitter, but it was later declared an
open-source project.
Features of Bootstrap:
Bootstrap boasts a treasure trove of pre-built components, including:
• Grid System: Construct layouts with ease using a flexible grid system that adapts
seamlessly to various screen sizes.
• Forms: Craft user-friendly forms with a variety of styles and functionalities like
validation.
• Buttons: Spice up your website with customizable buttons in all shapes and sizes.
• Navigation: Implement user-friendly navigation menus, from simple dropdowns to
complex mega menus.
• Alerts: Convey messages effectively through dismissible alerts, warnings, and
success notifications.
• Images: Enhance your website’s visual appeal with responsive image management.
• JavaScript Plugins: Incorporate interactive elements like modals, tooltips, and
carousels with Bootstrap’s JavaScript plugins.
Building with Bootstrap Components
Bootstrap provides a rich assortment of pre-built components to expedite your
development process. Let’s explore some widely used ones:
• Buttons: Implement buttons with various styles, sizes, and functionalities using
classes like .btn-primary and .btn-outline-success.
• Alerts: Convey messages through dismissible alerts with semantic classes
like .alert-success and .alert-danger.
• Images: Incorporate responsive images using the .img-fluid class, ensuring they
scale appropriately across devices.
• Navigation: Craft navigation menus using Bootstrap’s navbar component, which
includes support for responsive collapsing on smaller screens.
Introduction to AngularJS
AngularJS is a popular open-source framework that simplifies web development
by creating interactive single-page applications (SPAs). Unlike traditional websites
that load new pages for each click, SPAs offer a smoother user experience by updating
content on the same page.
AngularJS makes this possible by transforming static HTML into dynamic content that
adapts to user interactions. Features like data binding and dependency injection
streamline development, saving you time and effort. With regular updates and a large
community, AngularJS ensures your web applications stay modern and efficient.
PHP
PHP is a popular scripting language used for creating dynamic web pages and web
applications. The term PHP is an acronym of Hypertext Preprocessor. It is an open-
source, interpreted, object-oriented server-side scripting language.
Features of PHP
• Open-Source and Free: PHP is firstly open source which means anyone can use
PHP code without any licensing. Along with this one can run PHP on any operating
system like Windows, macOS, Linux, Unix and more.
• PHP Server-Side Scripting: PHP code executes on the server before sending HTML
content to the user’s browser, allowing for the dynamic generation of web pages and
handling user interactions.
• Interpreted language: PHP code is interpreted line by line, eliminating the need for
compilation and simplifying development and testing processes.
• Database connectivity: PHP integrates seamlessly with various databases like
MySQL, PostgreSQL, and Oracle, facilitating data storage and retrieval for web
applications.
• Object-oriented programming (OOP): PHP supports OOP concepts like classes,
objects, inheritance, and polymorphism, enabling better code organization and
modularity.
• Built-in functions: PHP comes with a rich set of built-in functions for various tasks
such as string manipulation, date and time handling, file handling, and more, reducing
the need for external libraries.
• Session management: PHP allows for user session management, enabling
personalized experiences and storing user data across multiple page visits.
• Security features: While security considerations are essential for any development
language, PHP offers several built-in security features and best practices to help
mitigate vulnerabilities.
PHP Characteristics
1. Simple
2. Efficient
3. Secure
4. Flexible
Node.js
Node.js (Node js) is an open-source and cross-platform JavaScript runtime
environment. It runs on Chrome’s V8 JavaScript engine. It allows developers to run
JavaScript code on the server. Node.js enables developers to get into the server-side
world.