Web Design and Programming Module
Web Design and Programming Module
INSTITUTE OF TECHNOLOGY
FACULTY OF COMPUTING AND SOFTWARE ENGINEETING
Web design and Programming Lecture Notes
By: Chala Simon
Learning Outcomes:
• Build websites, web frameworks using basic HTML, CSS and JavaScript
• Build Web APIs that are read for many client-side applications
• You can connect as many computers as you wish. But it gets complicated
quickly. If you're trying to connect, say, ten computers, you need 45 cables,
with nine plugs per computer!
• Such a network comes very close to what we call the Internet, but we're
missing something. How can we connect and handle the connection between
our network and rest of world? Therefore, we need more infrastructure.
• To do that, we will connect our network to an Internet Service Provider (ISP).
An ISP is a company that manages some special routers that are all linked
together and can also access other ISPs' routers. So, the message from our
network is carried through the network of ISP networks to the destination
network. The Internet consists of this whole infrastructure of networks.
• Clients are the typical web user's internet-connected devices (for example, your
computer connected to your Wi-Fi, or your phone connected to your mobile network)
and web-accessing software available on those devices (usually a web browser like
Firefox or Chrome).
• web server
A web server is software and hardware that uses HTTP (Hypertext Transfer Protocol)
and other protocols to respond to client requests made over the World Wide Web.
The main job of a web server is to display web content through storing, processing and
delivering webpages to users.
A URL for HTTP (or HTTPS) is normally made up of three or four components:
A scheme - identifies the protocol to be used to access the resource on the
Internet. It can be HTTP (without SSL) or HTTPS (with SSL).
Host name - is the domain name which identifies the host that holds the
resource.
A path – is the path name which identifies the specific resource in the host
that the web client wants to access.
A query string - If a query string is used, it follows the path component,
and provides a string of information that the resource can use for some
purpose (for example, as parameters for a search or as data to be
processed).
scheme://host:port/path?query
Programming vs Scripting
compressed into smaller packages that do not need written in one language and
to be interpreted by another language or interpreted within another program. For
application. instance, JavaScript has to be incorporated
within HTML, which the Internet browser
will then interpret.
Hosting is not required Require hosting
Getting started with the web is a concise series introducing you to the practicalities of web
development. You'll set up the tools you need to construct a simple webpage and publish your
own simple code.
Before you start writing the code for your website, you should plan it first.
o What information are you showcasing?
o What fonts and colors are you using?
o Outline a simple method that you can follow to plan out your site's content and
design.
A website consists of many files: text content, code, stylesheets, media content, and so
on.
When you're building a website, you need to assemble these files into a sensible
structure and make sure they can talk to one another.
The scripts may be created in two ways: on the client side or the server side, where the
server-side scripts are processed on a server. In contrast, client-side scripting needs browsers
to execute scripts on the client system but doesn't connect with the server executing the
client-side scripts.
Client-Side Scripting refers to the output which is requested to the server by the end-users.
The majority of this page is written in HTML. With client-side scripting, JavaScript is the
primary language used. It is the most widely used language in this area, and it works with
all programs.
The client-side scripting may significantly reduce server demand. It is intended to be utilized
as a scripting language with a web browser as the host program. The HTML and CSS are
delivered as plain text when a user uses a browser to request a webpage from the server, and
the browser understands and renders the web content at the client end.
CSS
CSS is an abbreviation for Cascading Style Sheets. It provides a technique for creating
graphic elements that help a web application's appearance look more appealing. A style tag
in a web page defines all the specifics regarding the web page's presentation, including its
border styles, image styles, colour, font styles, borders, format, font size, margins, padding,
etc.
JavaScript
It is a client-side scripting language designed for a specific purpose, but several JavaScript
frameworks are already utilized as server-side scripting technologies.
VBScript
VBScript is based on Visual Basic, which was created by Microsoft in 1996. It is a scripting
programming language that is lightweight, fast, and easy to learn. It is not a OOPs language
but is similar to JavaScript.
Server-side scripting is a programming technique for creating code that may run software
on the server side. In other words, server-side scripting is any scripting method that may
operate on a web server. At the server end, actions such as website customization, dynamic
changes in website content, response creation to user requests, database access, and many
more are carried out.
The server-side is made up of three parts: the database, the server, the APIs, and the
backend web software written in the server-side scripting language. When a browser
requests a page with server-side scripting, the web server evaluates the script before
delivering the page to the browser. In this case, script processing may entail collecting
information from a database, performing simple computations, or selecting the relevant
material to be shown on the client end. The output is provided to the web browser when the
script is processed. The web server hides the scripts from the end user until the content is
delivered, making the data and source code safer.
Python
It is an open-source language that is very powerful and easy to learn. It is suitable for
beginners because it is simple to learn and read. It is believed to be used by Google and
YouTube. It is a OOPs language with dynamic typing and data structures. It has grown to be
one of the most popular languages for both quick application development and web
development.
Ruby
It is a free and open-source programming language that was developed and firstly introduced
in the early 1990s. It is a dynamic language that is simple to read and write and an OOPs
language that is interpreted as it runs. It has evolved continuously since its development and
is one of the most utilized web development languages.
There are various features of server-side scripting. Some main features of the server-side
scripting are as follows:
1. It is connected with data access, error handling, and data processing speed.
2. It is processed and interacts with the server.
3. Using a highly integrated programming language makes it more secure than client-
side scripting.
The opening tag: This consists of the name of the element (in this case, p),
wrapped in opening and closing angle brackets. This states where the element
begins or starts to take effect — in this case where the paragraph begins.
The closing tag: This is the same as the opening tag, except that it includes a
forward slash before the element name. This states where the element ends — in
this case where the paragraph ends. Failing to add a closing tag is one of the
standard beginner errors and can lead to strange results.
The content: This is the content of the element, which in this case, is just text.
The element: The opening tag, the closing tag, and the content together comprise
the element.
Elements can also have attributes that look like the following:
Attributes contain extra information about the element that you don't want to appear in
the actual content. Here, class is the attribute name and "nice" is the attribute value.
The class attribute allows you to give the element a non-unique identifier that can be
used to target it (and any other elements with the same class value) with style
information and other things. Some attributes have no value, such as "required".
A space between it and the element name (or the previous attribute, if the element
already has one or more attributes).
The attribute name followed by an equal sign.
The attribute value wrapped by opening and closing quotation marks.
1 It’s a document type declaration (also called DOCTYPE declaration) that identifies this
document as an HTML5 document. It lets modern browsers know they should interpret
the document as written according to the HTML5 specification.
2 The entire document is contained within an html element. The html element is called
the root element because it contains all the elements in the document, and it may not be
contained within any other element. It is used for both HTML and XHTML documents.
3 Within the html element, the document is divided into a head and a body. The head
element contains descriptive information about the document itself, such as its title, the
style sheet(s) it uses, scripts, and other types of “meta” information.
4 The meta elements within the head element provide information about the document
itself. A meta element can be used to provide all sorts of information, but in this case, it
specifies the character encoding (the standardized collection of letters, numbers, and
symbols) used in the document.
5 Also in the head is the mandatory title element. According to the HTML specification,
every document must contain a descriptive title.
6 Finally, the body element contains everything that we want to show up in the browser
window.
An "element" is a single part of a webpage. Some elements are large and hold smaller elements
like containers. Some elements are small and are "nested" inside larger ones. By default, "inline
elements" appear next to one another in a webpage. They take up only as much width as they need
in a page and fit together horizontally like words in a sentence or books shelved side-by-side in a
row. All inline elements can be placed within the <body> element.
"Block elements," on the other hand, take up the entire width of a webpage. They also take
up a full line of a webpage; they do not fit together side-by-side. Instead, they stack like
paragraphs in an essay or toy blocks in a tower.
CSS allows web designers to control various aspects of a web page's appearance, including
its color scheme, typography, layout, and visual effects such as animations and transitions. It
provides a wide range of styling options, including basic properties such as font-size, color,
and background, as well as more advanced techniques such as positioning, responsiveness,
and media queries.
• Separation of concerns: Separating the presentation and layout of a web page from its
content makes it easier to maintain and update the site's design. With CSS,
developers can make changes to the style of a site without having to modify the
content of each individual page.
• Consistency: Using style sheets across a site ensures that the site's visual appearance
is consistent across all pages, which can help establish a sense of brand identity.
• Efficiency: CSS can improve web page loading times by reducing the amount of code
needed in HTML. With CSS, developers can define the style of a page using fewer
lines of code than would be required using HTML alone.
• Accessibility: Separating the style of a web page from its content can make it easier
for assistive technologies (such as screen readers) to navigate and read the page.
• HTML: HTML is used to create the structure of a web page, including headings,
paragraphs, lists, images, and links. Here's an example of what HTML might look like
for a simple web page:
<!DOCTYPE html>
<html>
<head>
<title>My Web Page</title>
</head>
<body>
<h1>Welcome to my web page!</h1>
<p>This is a paragraph of text.</p>
<img src="image.jpg" alt="An image">
<a href="http://www.example.com">Click here to visit Example.com</a>
</body>
</html>
Page | 18 AMiT- FCSE By: Chala Simon
• CSS: CSS is used to define the visual appearance of a web page, including the colors,
fonts, layout, and other design elements. Here's an example of what CSS might look
like for the HTML above:
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
}
h1 {
color: blue;
}
p{
font-size: 18px;
line-height: 1.5;
}
img {
width: 100%;
}
a{
color: red;
text-decoration: none;
}
In this example, we've defined the font-family and background-color for the 'body'
element, the color for the 'h1' element, the font-size and line-height for the 'p' element, the
width for the img element, and the color and text-decoration for the 'a' element.
• Each declaration includes a CSS property name and a value, separated by a colon.
• A CSS declaration always ends with a semicolon, and declaration blocks are
surrounded by curly braces.
• External Style Sheet: In this method, the CSS code is stored in a separate file with
a .css extension, and then linked to the HTML document using the <link> element in
the <head> section of the HTML document. Here's an example:
<!DOCTYPE html>
<html>
<head>
<title>My Web Page</title>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<h1>Welcome to my web page!</h1>
<p>This is a paragraph of text.</p>
</body>
</html>
In this example, the href attribute specifies the location of the external style sheet
file, which contains the CSS rules for the web page.
• Internal Style Sheet: In this method, the CSS code is included within the <style>
element in the <head> section of the HTML document. Here's an example:
<!DOCTYPE html>
<html>
<head>
<title>My Web Page</title>
<style>
body {
background-color: #f0f0f0;
}
h1 {
color: blue;
}
</style>
</head>
<body>
<h1>Welcome to my web page! </h1>
<p>This is a paragraph of text.</p>
</body>
</html>
• Inline Style: In this method, the CSS code is included directly within the HTML
elements using the style attribute. Here's an example:
<!DOCTYPE html>
<html>
<head>
<title>My Web Page</title>
</head>
<body>
<h1 style="color: blue;">Welcome to my web page!</h1>
<p style="font-size: 18px;">This is a paragraph of text.</p>
</body>
</html>
In this example, the CSS rules are included within the style attribute of each HTML
element. This method is generally not recommended, as it can be difficult to maintain
and update the CSS code when it is scattered throughout the HTML document.
CSS Selectors
CSS selectors are used to target specific HTML elements on a web page and apply styling
rules to them. There are several types of selectors in CSS, each with its own syntax and level
of specificity. Understanding CSS selectors is a crucial part of mastering CSS and creating
effective styles for your web pages.
p{
color: red;
}
In this example, the 'p' selector targets all <p> elements on the page and applies the
color property with a value of "red".
In this example, the .my-class selector targets all HTML elements that have the
class attribute set to "my-class" and applies the font-size property with a value of
"18px".
3. ID Selectors: ID selectors target a specific HTML element that has a specific ID
attribute. They are indicated by a hash (#) followed by the ID name. Here's an
example:
#my-element {
background-color: blue;
}
In this example, the #my-element selector targets the HTML element with the ID
attribute set to "my-element" and applies the background-color property with a
value of "blue".
A combinator selector
A combinator selector in CSS is used to select elements based on their relationship to other
elements on the page. There are several types of combinator selectors in CSS, each with its
own syntax and purpose.
Descendant Selector (Space): This selector targets elements that are descendants of a
specific parent element. It is indicated by a space between two or more selectors. For example:
ul li {
color: red;
}
In this example, the li element will be selected only if it is a descendant of a ul element. The
ul element may have other parent elements as well.
Child Selector (>): This selector targets elements that are direct children of a specific
parent element. It is indicated by a greater than symbol (>) between two selectors. For
example:
ul > li {
color: red;
}
Adjacent Sibling Selector (+): This selector targets an element that comes immediately
after another specific element. It is indicated by a plus (+) sign between two selectors. For
example:
h1 + p {
color: red;
}
In this example, the p element will be selected only if it immediately follows an h1 element.
General Sibling Selector (~): This selector targets elements that are siblings of a specific
element. It is indicated by a tilde (~) between two selectors. For example:
h1 ~ p {
color: red;
}
In this example, all p elements that follow an h1 element will be selected, regardless of
whether they immediately follow it or not.
Combinator selectors are a powerful tool in CSS that allow you to target specific elements on
the page based on their relationship to other elements. By mastering the use of combinator
selectors, you can create complex and precise styles that enhance the overall user experience.
element element div p Selects all <p> elements inside <div> elements
element>element div > p Selects all <p> elements where the parent is a <div>
element
element+element div + p Selects the first <p> element that are placed
immediately after <div> elements
Cascading Order
• What style will be used when there is more than one style specified for an HTML
element?
• Order:
• Inline style (inside an HTML element)
• External and internal style sheets (in the head section)
• Browser default
Here is a CSS cheatsheet that includes some of the most commonly used CSS properties:
Selector
Selector Description
element element Selects all elements that are descendants of the specified element
element > element Selects all elements that are direct children of the specified element
Box Model
Property Description
width Sets the width of an element
height Sets the height of an element
margin Sets the margin around an element
padding Sets the padding inside an element
border Sets the border around an element
Typography
Property Description
Property Description
Display
Property Description
Positioning
Property Description
top, right, bottom, left Sets the offset for a positioned element
Flexbox
Property Description
Property Description
Client-side programming refers to the practice of writing code that executes within a user's
web browser. When a user visits a website, the web server sends the HTML, CSS, and
JavaScript files to the user's browser. The browser then interprets the code and renders the
web page. Client-side programming is used to add interactivity, validate form inputs, perform
animations, and make AJAX calls to fetch data from a server without reloading the page.
What is JavaScript?
• Validating form inputs: JavaScript can be used to ensure that users enter valid
information into forms, such as email addresses, phone numbers, and credit card
numbers.
• Creating animations: JavaScript can be used to animate web page elements, such
as buttons, menus, and images.
• Security: Because client-side scripts execute within the user's browser, they can be
vulnerable to attacks such as cross-site scripting (XSS) and code injection.
• Performance: JavaScript can slow down web page load times if it is not optimized
properly. Additionally, not all users may have the same level of JavaScript support in
their browsers.
• Accessibility: Users who have disabilities or who use assistive technologies may have
difficulty using websites that rely heavily on JavaScript.
JavaScript Terminology
Here are some common JavaScript terms that developers should be familiar with:
/*
This is a
multi-line
comment in JavaScript
*/
// Declare a variable called "message" and assign it the value "Hello, world!"
var message = "Hello, world!";
JavaScript code can be embedded directly into an HTML file using the <script> tag:
<!DOCTYPE html>
<html>
<head>
<title>My Web Page</title>
</head>
<body>
<h1>My Web Page</h1>
<script>
// This is a JavaScript program embedded in an HTML file
var message = "Hello, world!";
alert(message);
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>My Web Page</title>
<script src="my-script.js"></script>
</head>
<body>
<h1>My Web Page</h1>
</body>
</html>
In this example, the JavaScript code is stored in a file called "my-script.js", which is linked
to the HTML file using the src attribute of the <script> tag.
• alert(): This method displays a message in a dialog box that requires the user to click
"OK" to dismiss it. Here's an example:
alert("Hello, world!");
• console.log(): This method outputs a message to the console, which can be opened in
the browser's developer tools. This is useful for debugging purposes or for displaying
messages that the user doesn't need to see. Here's an example:
console.log("Hello, world!");
• document.write(): This method writes a message directly to the web page. However,
this method is not commonly used anymore because it can overwrite the existing
content of the page. Here's an example:
document.write("Hello, world!");
In this example, the message "Hello, world!" is displayed inside an HTML element
with the ID "my-element". Note that this method requires an existing HTML element
on the page to work.
• prompt(): This method displays a dialog box that prompts the user to enter a value.
The value entered by the user is returned as a string. Here's an example:
var name = prompt("What is your name?");
In this example, the user is prompted to enter their name. The name is then stored in
a variable called "name", which is used to display a personalized message in the
console.
• confirm(): Generates a message on pop up window with two options , yes or no
Javascript variable
In JavaScript, variables are used to store values that can be used later in the program. Here
are the basic syntax and rules for declaring and using variables in JavaScript:
1. Declaration: To declare a variable in JavaScript, use the var, let, or const keyword,
followed by the variable name and an optional initial value:
const PI = 3.14;
• 'var' is used to declare a variable that can be reassigned later in the program.
• 'let' is used to declare a variable that can be reassigned, but is limited to the block
scope.
• 'const' is used to declare a variable that cannot be reassigned and is also limited to
the block scope.
2. Naming rules: Variable names can contain letters, numbers, underscores, or dollar
signs. They cannot start with a number, and they cannot be a reserved keyword, such
as if, else, while, etc.
myVariable = 20;
console.log(myVariable); // Output: 20
5. Scope: JavaScript has two types of scope: global scope and local scope. Variables
declared outside a function have global scope and can be accessed from anywhere in the
program. Variables declared inside a function have local scope and can only be accessed
from within the function.
var globalVariable = "I am global";
function myFunction() {
myFunction();
In this example, the variable 'globalVariable' has global scope and can be accessed
from within the function 'myFunction' and outside of it. The variable 'localVariable'
has local scope and can only be accessed from within 'myFunction'.
1. Accessing Elements: JavaScript can access the HTML elements on a page using
methods like document.getElementById(), document.querySelector(), and
document.querySelectorAll(). These methods allow us to retrieve elements based
on their ID, class, or tag name.
3. Events: JavaScript can also listen for events on the web page, such as clicks,
mouse movements, and keyboard inputs. We can use event listeners to execute
code when an event occurs.
In this example, we add event listeners to an element and to the document, and execute code
when events occur.
While:
var i = 0
while (i < arrayName.length) {
//code to execute for each element in arrayName
i++;
}
Functions function functionname(parameter1,parameter2…)
{
//function body
}
Server-side programming refers to the execution of code on a web server to generate dynamic
web pages. It involves processing user requests, interacting with databases, and generating
output that is sent back to the client's web browser. Server-side programming is used to
create interactive web applications that require dynamic content.
Introduction to PHP
PHP (Hypertext Preprocessor) is a popular server-side scripting language used to create
dynamic web pages. It was originally created in 1994 by Rasmus Lerdorf and has since
become one of the most widely used programming languages on the web.
PHP is an open-source language and is constantly evolving, with new features and
improvements being added regularly. Some of the key features of PHP include:
• Web Server: A web server is software that allows you to serve web pages to clients
over the internet. Some of the popular web servers include Apache, Nginx, and IIS.
• PHP Interpreter: The PHP interpreter is the software that reads and executes PHP
code. You can download the latest version of the PHP interpreter from the official PHP
website.
• Database Management System: PHP is commonly used to interact with databases,
so you will need a database management system such as MySQL or PostgreSQL.
• Text Editor or Integrated Development Environment (IDE): A text editor or IDE
is used to write and edit PHP code. Some popular options include Visual Studio Code,
Sublime Text, and PhpStorm.
PHP code is executed on the server-side and can be embedded within an HTML document.
PHP code is enclosed in PHP tags, which are typically "<?php" and "?>". The code within the
tags is executed by the server and the output is sent to the web browser.
In the above example, the PHP code to display the current date is embedded within the
HTML tags. The "echo" statement is used to output the result to the web page.
Variables are used to store data in PHP. In PHP, variables are declared using the "$" symbol
followed by the variable name. For example, to declare a variable called "name", you would
use the following syntax:
$name = "John";
In the above example, the variable "name" is assigned the value "John". You can also declare
variables with a specific data type, such as integer or float. For example:
$age = 30;
$price = 9.99;
PHP is a loosely typed language, which means that you do not need to declare the data type
of a variable before using it. The data type is automatically determined based on the value
assigned to the variable.
PHP can be used to output text and HTML to the web browser. The "echo" statement is used
to output text or HTML to the web page. For example, to output the text "Hello, World!" to
the web page, you can use the following PHP code:
<?php
echo "Hello, World!";
?>
In the above example, the "echo" statement outputs the text "Hello, World!" to the web page.
<?php
echo "<h1>Welcome to My Website</h1>";
echo "<p>Thank you for visiting! </p>";
?>
In the above example, the "echo" statements output HTML code to the web page, which is
then rendered by the web browser.
PHP can be used to generate dynamic content based on user input or other variables. For
example, you can use PHP to generate a personalized greeting based on the user's name. To
do this, you would first need to capture the user's name using a form or other input method.
Once you have the user's name, you can use PHP to generate the personalized greeting. For
example:
<?php
$name = $_POST["name"];
echo "Hello, $name!";
?>
In the above example, the $_POST superglobal variable is used to capture the user's name
from a form. The variable $name is then used to generate the personalized greeting using
the "echo" statement.
$age = 30;
You can then use the variables in your code, either by referencing the variable name directly
or by concatenating the variable with other strings or variables. For example:
echo "My name is " . $name . " and I am " . $age . " years old.";
In the above example, the variables $name and $age are concatenated with other strings to
create a sentence that is output to the web page.
$name = "John";
In the above example, the variable $name is concatenated with the string "Hello, " to create
a personalized greeting that is output to the web page.
PHP provides a wide range of functions for manipulating numbers. You can perform
mathematical operations such as addition, subtraction, multiplication, and division using
basic arithmetic operators. For example:
$x = 10;
$y = 5;
$sum = $x + $y; // adds x and y together
$difference = $x - $y; // subtracts y from x
$product = $x * $y; // multiplies x and y together
$quotient = $x / $y; // divides x by y
You can also use functions such as round(), ceil(), and floor() to round numbers to the nearest
whole number, to the next highest whole number, or to the next lowest whole number,
respectively.
Constants are values that cannot be changed once they are defined. In PHP, you can define
constants using the define() function. For example:
define("PI", 3.14159);
echo PI; // outputs 3.14159
if (condition) {
// execute this code if the condition is true
}
For example:
$x = 10;
$y = 5;
if ($x > $y) {
echo "x is greater than y";
}
In the above example, the if statement checks whether the variable $x is greater than the
variable $y. If the condition is true, the message "x is greater than y" is output to the web
page.
Loops in PHP
Loops allow you to execute a block of code repeatedly. The most common loops in PHP are
the for loop, the while loop, and the do-while loop.
The for loop executes a block of code a specified number of times. The basic syntax of a for
loop is as follows:
The while loop executes a block of code as long as a certain condition is true. The basic syntax
of a while loop is as follows:
while (condition) {
// execute this code
}
For example:
$i = 0;
while ($i < 5) {
echo "The value of i is " . $i . "<br>";
$i++;
}
In the above example, the while loop executes the code block as long as the variable $i is less
than 5, incrementing $i each time.
The do-while loop is similar to the while loop, but it always executes the code block at least
once. The basic syntax of a do-while loop is as follows:
do {
} while (condition);
For example:
$i = 0;
do {
echo "The value of i is " . $i . "<br>";
$i++;
} while ($i < 5);
In the above example, the do-while loop executes the code block at least once, and then
continues to execute the block as long as the variable $i is less than 5.
For example:
In the above example, an array called $fruits is created, which contains the values "apple",
"banana", and "orange".
For example:
For example:
For example:
$name = 'John';
$message = "Hello $name!";
In the above example, the variable $name contains the string 'John', and the variable
$message contains the string "Hello John!".
$first_name = 'John';
$last_name = 'Doe';
$name = $first_name . ' ' . $last_name;
echo $name; // outputs "John Doe"
In the above example, the dot (.) operator is used to concatenate the $first_name and
$last_name variables, separated by a space.
Functions in PHP
A function is a block of code that performs a specific task. Functions are used to organize code
and make it more reusable. In PHP, you can create your own functions or use built-in
functions that are provided by the PHP language.
function sayHello($name) {
echo "Hello, $name!";
}
In the above example, the function sayHello takes one argument, $name, and echoes out a
message that includes the value of the $name argument.
$name = 'John';
sayHello($name); // outputs "Hello, John!"
In the above example, the function sayHello is called with the argument $name, which is set
to the value 'John'.
In the above example, the function multiply takes two arguments, $a and $b, and returns
their product. The function is called with the arguments 3 and 5, and the result is stored in
the variable $result.
In the above example, the function add takes two arguments, $a and $b, and returns their
sum. The function is called with the arguments 3 and 5, and the result is stored in the
variable $result.
To connect to a MySQL database using PHP, you need to use the mysqli or PDO extension.
Here's an example using the mysqli extension:
// Database configuration
$host = 'localhost';
$user = 'username';
$password = 'password';
$database = 'database';
In the above example, we use the SELECT statement to select all data from the users table.
We execute the query using the query() method of the mysqli object, and then loop through
the results using a while loop. We use the fetch_assoc() method to fetch each row of data as
an associative array, and then display the data on the screen.
4. Answer: c. <div>. The div tag is NOT a semantic HTML tag. The nav, article, and
footer tags are all examples of semantic HTML tags, which are used to add meaning
and structure to the content on a web page. The div tag, on the other hand, is a generic
container used for grouping and styling content.
5. Answer d. All of the above. JavaScript supports a range of data types, including
booleans, strings, and arrays.
6. Answer: d. jQuery. jQuery is not a web framework, but a JavaScript library designed
to simplify client-side scripting of HTML. The other options are all web frameworks:
React is a JavaScript library for building user interfaces, Angular is a TypeScript-
based open-source web application framework, and Django is a high-level Python web
framework that enables rapid development of secure and maintainable websites.
7. Answer: c. to style and format web pages, CSS is used to separate the presentation
of a web page from its content, allowing developers to control the layout, design, and
visual appearance of web pages. CSS can be used to control various aspects of a web
page's styling, including font size and type, color, background images, layout, and
8. Answer: c. hover, the "hover" event is not a valid event in JavaScript. The other
events listed, "click", "mouseover", and "scroll", are all valid events that can be used
to trigger JavaScript code.
9. JavaScript is used to add interactivity to web pages. While HTML is used for
the content and structure of a web page and CSS is used for styling and layout,
JavaScript is used to make the page interactive by allowing users to interact with
elements on the page, trigger actions and events, and dynamically update content
without having to refresh the page. PHP, on the other hand, is a server-side scripting
language used for web development that allows for the creation of dynamic web pages,
but it is not typically used for client-side interactivity.
10. All of the above options are CSS units of measurement. Pixels (px) and points
(pt) are absolute units that represent fixed sizes, while ems (em) is a relative unit that
represents the font-size of the element. These units are commonly used in CSS to
specify measurements for various properties such as width, height, font-size, margin,
padding, etc.
11. Answer: a. A web page is a single page, while a website is a collection of web
pages, A webpage is a single page, while a website is a collection of related pages with
a common homepage. Website includes navigation, search, and forms, while a
webpage is focused on displaying specific content.
12. Answer: c. Implementing media queries to adjust styling and layout based on
device characteristics. Implementing media queries is key to building a responsive
client-side application. Media queries allow developers to create device-specific
stylesheets, ensuring the application adapts to different viewing environments. A
fixed layout for all devices and not optimizing assets can lead to poor performance on
various devices.
15. Answer: c. To allow multiple client-side applications to access the API, the
main purpose of building web APIs is to enable many client-side apps to access the
API, providing a standard interface for different types of apps like web browsers,
mobile apps, and software programs. This widens the availability of data and services,
increasing the potential value of the application. Limiting access to specific apps or a
single app would restrict the API's usefulness and accessibility.
16. Answer: d. &backslash; This is not a valid character entity in HTML. The correct
escape sequence for a backslash is \
17. Answer: a. <meta charset="">. This tag is used in the head section of an HTML
document to specify the character encoding. The charset attribute specifies the
character encoding used for the document.
19. Answer: d. font-family, the font-family property is used to change the font family in
CSS. It specifies the name of the font family, such as "Arial" or "Times New Roman".
20. Answer: a. line-height: The line-height property is used to add spacing between lines
of text in CSS. It specifies the height of each line of text, which includes the space
between the lines.
22. Answer: a. width: The width property is used to specify the size of an element in
CSS. It specifies the width of the element, which can be specified in pixels,
percentages, or other units.
23. Answer: d. All of the above: The border-style, border-width, and border-color
properties are used together to add a border around an element in CSS. The border-
style property specifies the style of the border, such as "solid" or "dotted", the border-
width property specifies the width of the border, and the border-color property
specifies the color of the border.
24. Answer: a. '==' compares values, while '===' compares both values and types.
The '==' operator compares values without considering their data types, while '==='
compares both values and data types. For example, 5 == "5" would be true, but 5 ===
"5" would be false because 5 is a number and "5" is a string.
26. Answer: a. It returns the type of the given variable or expression. The typeof
operator in JavaScript returns a string indicating the type of the operand
29. Answer: b. A for loop is used for iterating over a fixed number of elements,
while a while loop is used for iterating until a certain condition is met. A for
loop is used when you know the number of times you need to loop through a block of
code, while a while loop is used when you don't know the number of times you need to
loop through a block of code.
32. Answer: a. ORM is used for SQL databases, while ODM is used for NoSQL
databases. ORM (Object Relational Mapping) maps objects to tables in SQL
databases, while ODM (Object Data Mapping) maps objects to documents in NoSQL
34. Answer: a. The GET method s ends data through the URL in the HTTP request
header, while the POST method sends data through the HTTP request body.
In PHP, the GET method is commonly used for retrieving data from a server, while
the POST method is commonly used for submitting data to a server.
35. Answer: b. To fetch a row from a result set as an array. The purpose of the
mysqli_fetch_array() function in PHP is to fetch a row from a result set as an array.
This function is used to retrieve a row of data from a result set returned by a SELECT
query, and it returns an array that corresponds to the fetched row. The array can be
indexed both numerically and by field name, which allows for easy access to the values
of the returned columns. The mysqli_fetch_array() function can be used with the
procedural or object-oriented style of the mysqli extension in PHP, which provides
access to the MySQL database server.