AIT Solved Paper
AIT Solved Paper
Pattern)
(Semester - II)
Time : 2½ Hours] [Max. Marks : 50 ]
Instructions to the candidates:
1) All questions are compulsory.
2) Draw neat and labeled diagram wherever necessary.
PA-2558 [Total No. of Pages : 4
c) Which of the property in CSS used to change the background color of an element
is______
i) Bgcolor
ii) Color
iii) Background-color
iv) All of the above
v) Ans-iii) Background-color
d) Which selector is used to selects the elements that are the default among a set of
similar elements?
i) : : after
ii) : disabled
iii) : default
iv) : checked
Ans-iii) :default
i) REPL is for
I) Research Eval Program Learn
II) Read Eval Print Loop
III) Read Earn Point Learn
IV) Read Eval Point Loop
Ans-II) Read Eval Print Loop
l) AngularJS is a________framework
i) HTML
ii) Java
iii) Javascript
iv) SQL
Ans- iii) Javascript
In order to use Node.js core or NPM modules, you first need to import it using require()
function as shown below.
As per above syntax, specify the module name in the require() function. The require()
function will return an object, function, property or any other JavaScript type,
depending on what the specified module returns.
The following example demonstrates how to use Node.js http module to create a web
server.
Syntax:
const module = require('module_name');
The require() function will return a JavaScript type depending on what the
particular module returns. The following example demonstrates how to use the
Node.js http module to create a web server.
process provides information and control about the current Node.js process.
querystring utility used for parsing and formatting URL query strings.
Local Modules: Unlike built-in and external modules, local modules are created
locally in your Node.js application. Let’s create a simple calculating module that
calculates various operations. Create a calc.js file that has the following code:
exports.add = function (x, y) {
return x + y;
};
Output:
Addition of 50 and 10 is 60
Subtraction of 50 and 10 is 40
Multiplication of 50 and 10 is 500
Division of 50 and 10 is 5
Note: This module also hides functionality that is not needed outside of the module.
Third-party modules: Third-party modules are modules that are available online
using the Node Package Manager(NPM). These modules can be installed in the
project folder or globally. Some of the popular third-party modules are Mongoose,
express, angular, and React.
Example:
npm install express
npm install mongoose
npm install -g @angular/cli
Node.js Local Module
Local modules are modules created locally in your Node.js application. These
modules include different functionalities of your application in separate files and
folders. You can also package it and distribute it via NPM, so that Node.js
community can use it. For example, if you need to connect to MongoDB and fetch
data then you can create a module for it, which can be reused in your application .
Writing Simple Module
Let's write simple logging module which logs the information, warning or error to the
console.
In Node.js, module should be placed in a separate JavaScript file. So, create a Log.js
file and write the following code in it.
var log = {
info: function (info) {
console.log('Info: ' + info);
},
warning:function (warning) {
console.log('Warning: ' + warning);
},
error:function (error) {
console.log('Error: ' + error);
}
};
module.exports = log
Log.js
In the above example of logging module, we have created an object with three
functions - info(), warning() and error(). At the end, we have assigned this object
to module.exports. The module.exports in the above example exposes a log object as
a module.
The module.exports is a special object which is included in every JS file in the Node.js
application by default. Use module.exports or exports to expose a function, object or
variable as a module in Node.js.
To use local modules in your application, you need to load it using require() function
in the same way as core module. However, you need to specify the path of JavaScript
file of the module.
The following example demonstrates how to use the above logging module contained
in Log.js.
app.js
myLogModule.info('Node.js started');
In the above example, app.js is using log module. First, it loads the logging module
using require() function and specified path where logging module is stored. Logging
module is contained in Log.js file in the root folder. So, we have specified the path
'./Log.js' in the require() function. The '.' denotes a root folder.
The require() function returns a log object because logging module exposes an object
in Log.js using module.exports. So now you can use logging module as an object and
call any of its function using dot notation e.g myLogModule.info() or
myLogModule.warning() or myLogModule.error()
Run the above example using command prompt (in Windows) as shown below.
Thus, you can create a local module using module.exports and use it in your
application.
Here, you will learn how to expose different types as a module using module.exports.
The module.exports is a special object which is included in every JavaScript file in the
Node.js application by default. The module is a variable that represents the current
module, and exports is an object that will be exposed as a module. So, whatever you
assign to module.exports will be exposed as a module.
Export Literals
Message.js
module.exports = 'Hello world'
Now, import this message module and use it as shown below.
var msg = require('./Message.js');
console.log(msg);
app.js
Run the above example and see the result, as shown below.
Hello World
Note:
You must specify ./ as a path of root folder to import a local module. However, you do
not need to specify the path to import Node.js core modules or NPM modules in
the require() function.
Export Object
The exports is an object. So, you can attach properties or methods to it. The following
example exposes an object with a string property in Message.js file.
Message.js
//or
console.log(msg.SimpleMessage);
In the above example, the require() function will return an object { SimpleMessage :
'Hello World'} and assign it to the msg variable. So, now you can
use msg.SimpleMessage.
Run the above example by writing node app.js in the command prompt and see the
output as shown below.
C:\> node app.js
Hello World
In the same way as above, you can expose an object with function. The following
example exposes an object with the log function as a module.
Log.js
module.exports.log = function (msg) {
console.log(msg);
};
The above module will expose an object- { log : function(msg){ console.log(msg); }
} . Use the above module as shown below.
app.js
msg.log('Hello World');
Hello World
data.js
module.exports = {
firstName: 'James',
lastName: 'Bond'
}
app.js
var person = require('./data.js');
console.log(person.firstName + ' ' + person.lastName);
Run the above example and see the result, as shown below.
C:\> node app.js
James Bond
NgIf
he NgIf directive is used when you want to display or remove an element based on a
condition.
If the condition is false the element the directive is attached to will be removed from
the DOM.
Important
The difference between [hidden]='false' and *ngIf='false' is that the first method
simply hides the element. The second method with ngIf removes the element
completely from the DOM.
We define the condition by passing an expression to the directive which is evaluated
in the context of its host component.
ngIf is used to display or hide the DOM Element based on the expression value
assigned to it. The expression value may be either true or false.
Let’s add an NgIf directive to the template so we only show the element if the age is
less than 30, like so:
TypeScript
Copy@Component({
selector: 'ngif-example',
template: `
<h4>NgIf</h4>
<ul *ngFor="let person of people">
<li *ngIf="person.age < 30"> (1)
{{ person.name }} ({{ person.age }})
</li>
</ul>
`
})
class NgIfExampleComponent {
people: any[] = [
{
"name": "Douglas Pace",
"age": 35
},
{
"name": "Mcleod Mueller",
"age": 32
},
{
"name": "Day Meyers",
"age": 21
},
{
"name": "Aguirre Ellis",
"age": 34
},
{
"name": "Cook Tyson",
"age": 32
}
];
}
Example of *ngIf:
<div *ngIf="false">
This text will be hidden
<h1 [ngStyle]="{'color':'#FF0000'}">
Structural Directive Example
</h1>
</div>
<div *ngIf="true">
This text will be displayed
<h1 [ngStyle]="{'color':'#00FF00'}">
Structural Directive Example
</h1>
</div>
Output:
OUTPUT
DYP 1
DYP 2
DYP 3
DYP 4
DYP 5
4. *ngSwitch :
ngSwitch is used to choose between multiple case statements defined by the
expressions inside the *ngSwitchCase and display on the DOM Element according to
that. If no expression is matched, the default case DOM Element is displayed.
Syntax:
<div [ngSwitch]="expression">
<div *ngSwitchCase="expression_1"></div>
<div *ngSwitchCase="expression_2"></div>
<div *ngSwitchDefault></div>
</div>
In the above syntax, the expression is checked with each case and then the case
matching with the expression is rendered on DOM else the Default case is rendered
on the DOM.
<div [ngSwitch]="'one'">
<div *ngSwitchCase="'one'">One is Displayed</div>
<div *ngSwitchCase="'two'">Two is Displayed</div>
<div *ngSwitchDefault>Default Option is Displayed</div>
</div>
In the above example, the expression ‘one’ in ngSwitch is matched to the expression
in ngSwitchCase. Hence, the Element displayed on DOM is ” One is Displayed “.
Output:
One is Displayed
We can use it to provide functionality in our web application. Each service performs a
specific task.
Service is a piece of reusable code with a focused purpose. A code that you will use
across multiple components in your application.
Our components need to access the data. You can write data access code in each
Component, but this is very inefficient and breaks the rule of single responsibility. The
Component should focus on presenting the data to the user.
The task of receiving data from the back-end server should be delegated to another class.
We call a class a service class because it provides each Component with the data it needs.
An Angular service is just a JavaScript function. All we have to do is create a class and
add methods and properties. Then we can create an instance of this class in our
Component and call its methods.
One of the best uses of services is to get data from a data source. Let us create a simple
service, which receives product data and sends it to our Component.
Product Model
Please create a new file under the folder src/app and call it product.ts
product.ts
Please create a new file under the src/app folder and call it
product.service.ts.product.service.ts
import {Product} from './product'
xport class ProductService{
public getProducts() {
let products:Product[];
products=[
new Product(1,'Memory Card',500),
new Product(1,'Pen Drive',750),
new Product(1,'Power Bank',100)
]
return products;
}
Next, create a ProductService class and export it. We need to export so that
components and other service classes import it and use it
The Get Products method returns a collection of products. In this example, we have
hardcoded the products. In real life, you would send an HTTP GET request to your
back end API to get the data service is ready.
Note that the above class is a simple JavaScript function. There is nothing angular
about it.
The Next step is to invoke the ProductService from the Component. Open the
app.componet.ts and add the following code.
app.component.ts
The getProducts method calls the getProducts method of the ProductService. It returns a
list of products, which we store in local variable products.
b) Write a program to read the query string using url property in Node js[5]
The Query String module used to provides utilities for parsing and formatting URL
query strings.It can be used to convert query string into JSON object and vice-versa.
The Query String is the part of the URL that starts after the question mark(?).
Requiring Module: You can include the module using the following code:
querystring.decode()
querystring.encode()
querystring.escape(str)
querystring.parse(str[, sep[, eq[, options]]])
querystring.stringify(obj[, sep[, eq[, options]]])
querystring.unescape(str)
Query String methods with description
Let us look into a real example to understand the important Query string methods.
Let us setup a basic Node application by giving the command npm init -y in
terminal, inside a folder. I had created an empty NodeJS folder for the same.
querystring.parse() Method
The querystring.parse() method is used to parse the URL query string into an object
that contains the key value pair. The object which we get is not a JavaScript object,
so we cannot use Object methods like obj.toString, or obj.hasOwnProperty().
The latest UTF-8 encoding format is assumed unless we specify a different encoding
format. But we should stick to UTF-8 encoding as it is the standard and contains all
international characters like the Chinese characters and the hindi characters. After
that also if we need alternative character encoding, then
the decodeURIComponent option should be used.
As seen from the above syntax the method accepts four parameters, and they are
described below.
str: This is the only required string field and it specifies the query string that has
to be parsed.
sep: It is an optional string field, which if given specifies the substring used to
delimit the key and value pairs in the query string. The default value which is
generally used is “&”.
eq: It is an optional string field that specifies the substring used to delimit keys
and values in the query string. The default value which is generally used is “=”.
options: It is an optional object field which is used to modify the behaviour of
the method. It can have the following parameters:
decodeURIComponent: It is a function that would be used to specify
the encoding format in the query string. The default value is
querystring.unescape(), about which we will learn later.
maxKeys: It is the number which specifies the maximum number of
keys that should be parsed. A value of “0” would remove all the
counting limits, and it can parse any number of keys. The default value
is set at “1000”.
The below example shows the various options used in querystring.parse() method.
Add the below code in querystring.js file, which we created earlier
Now, run the command node querystring.js from the Integrated terminal in VSCode
or any terminal. Note that you need to be inside the folder NodeJS, which we had
created earlier. The output of the same will be below.
querystring.stringify() Method
It can be used to convert the string, numbers and Boolean values for the ke y. You
can also use an array of string, numbers or Boolean as values. This method of
changing an object to query string is called serialized.
The latest UTF-8 encoding format is assumed unless we specify a different encoding
format. But we should stick to UTF-8 encoding as it is the standard and contains all
international characters like the Chinese characters and the Hindi characters. If we
still need an alternative character encoding, then the decodeURIComponent option
should be used.
As from the above syntax the method accepts four parameters, and they are described
below.
obj: This is the only required object field and it specifies the object that has to
be serialized.
sep: It is an optional string field, which if given specifies the substring used to
delimit the key and value pairs in the query string. The default value which is
generally used is “&”.
eq: It is an optional string field that specifies the substring used to delimit keys
and values in the query string. The default value which is generally used is “=”.
options: It is an optional object field which is used to modify the behaviour of
the method. It can have the following parameters:
decodeURIComponent: It is a function that would be used to specify
the encoding format in the query string. The default value is
querystring.escape(), about which we will learn later.
The below example shows the various options used in querystring.stringify()
method. Add the below code in querystring.js file, which we created
earlier.queryString);
Now, run the command node querystring.js from the Integrated terminal in VSCode
or any terminal. Note that you need to be inside the folder NodeJS, which we had
created earlier. The output of the same will be below.
Query String
1: name=nabendu&access=true&role=developer&role=architect&role=manager
Query String 2: name:Parag, access:false, role:editor, role:HR
Query String 3: name==Parag&&&access==false&&&role==editor&&&role==HR
querystring.decode() Method
As earlier, run the command node querystring.js from a terminal. And the output will
be same as that with querystring.parse() method.: 'false' }
querystring.encode() Method
querystring.escape(str) Method
querystring.unescape(str) Method
name=Testing&company=GeeksforGeeks&
content=Article&date=9thMarch2021
Q3) a) What is NPM? How packages installed locally and globally? [5]
The npm comes bundled with Node.js installables in versions after that v0.6.3. You can
check the version by opening Node.js command prompt and typing the following
command:
1. npm version
Installing Modules using npm
Open the Node.js command prompt and execute the following command:
By default, npm installs dependency in local mode. Here local mode specifies the folder
where Node application is present. For example if you installed express module, it
created node_modules directory in the current directory where it installed express
module.
You can use npm ls command to list down all the locally installed modules.
The Node.js module is uninstalled. You can verify by using the following command:
npm ls
Searching a Module
1. local packages are installed in the directory where you run npm install <package-
name>, and they are put in the node_modules folder under this directory
2. global packages are all put in a single place in your system (exactly where
depends on your setup), regardless of where you run npm install -g <package-
name>
b) Create angular program which will demonstrate the usage of component directive.
[5]
The answer is in your practical file.
OR
a) What are the Typesoript components? [5]
Components of TypeScript
The TypeScript language is internally divided into three main layers. Each of these layers
is divided into sublayers or components. In the following diagram, we can see the three
layers and each of their internal components. These layers are:
1. Language
2. The TypeScript Compiler
3. The TypeScript Language Services
1. Language
The TypeScript compiler (TSC) transform the TypeScript program equivalent to its
JavaScript code. It also performs the parsing, and type checking of our TypeScript code
to JavaScript code.
Browser doesn't support the execution of TypeScript code directly. So the program
written in TypeScript must be re-written in JavaScript equivalent code which supports
the execution of code in the browser directly. To perform this, TypeScript comes with
TypeScript compiler named "tsc." The current version of TypeScript compiler supports
ES6, by default. It compiles the source code in any module like ES6, SystemJS, AMD,
etc.
The TypeScript compiler configuration is given in tsconfig.json file and looks like the
following:
{
"compilerOptions": {
"declaration": true,
"emitDecoratorMetadata": false,
"experimentalDecorators": false,
"module": "none",
"moduleResolution": "node",
"noFallthroughCasesInSwitch": false,
"noImplicitAny": false,
"noImplicitReturns": false,
"removeComments": false,
"sourceMap": false,
"strictNullChecks": false,
"target": "es3"
},
"compileOnSave": true
}
Declaration file
The language service provides information which helps editors and other tools to give
better assistance features such as automated refactoring and IntelliSense. It exposes an
additional layer around the core-compiler pipeline. It supports some standard typical
editor operations like code formatting and outlining, colorization, statement completion,
signature help, etc.
b) Write a program using NPM which will convert entered string into lower case &
upper case.
</body>
</html>
output
<body>
<p>Audio Sample</p>
<body>
<p>Audio Sample</p>
</body>
</html>
Example 5 (Adding audio with multiple sources): Multiple sources of audios are
specified so that if the browser is unable to play the first source, then it will
automatically jump to the second source and try to play it.
<!DOCTYPE html>
<html>
<body>
<p>Audio Sample</p>
</body>
</html>
Example 6 (Adding audio using the “Embed” tag): Adding audios to a
webpage using the “embed” tag is an old technique. This method does work,
but is comparatively less efficient than the other methods. The user must have
a plugin like MIDI or QuickTime because the embed tag requires a plugin for
support.
!DOCTYPE html>
<html>
<body>
<p>Audio Sample</p>
<?php
echo "
";
?>
PHP include() Function: The include() function in PHP is basically used to include
the contents/code/data of one PHP file to another PHP file. During this process if
there are any kind of errors then this include() function will pop up a warning but
unlike the require() function, it will not stop the execution of the script rather the
script will continue its process. In order to use this include() function, we will first
need to create two PHP files. Using the include() function, include one PHP file into
another one. After that, you will see two PHP files combined into one HTML file.
Example 2:
<html>
<body>
<h1>Welcome to geeks for geeks!</h1>
<p>Myself, Gaurav Gandal</p>
<p>Thank you</p>
<?php
echo "
?>
include() require()
The include() function does not stop the The require() function will stop the
execution of the script even if any error execution of the script when an error
occurs. occurs.
The include() function does not give a The require() function gives a fatal
fatal error. error
The include() function will only produce a The require() will produce a fatal
warning (E_WARNING) and the script error (E_COMPILE_ERROR) along
will continue to execute. with the warning.
OR
a) What are semantic elements and how it works in HTML5? [4]
What are Semantic Elements?
A semantic element clearly describes its meaning to both the browser and the
developer.
Examples of non-semantic elements: <div> and <span> - Tells nothing about its
content.
Examples of semantic elements: <form>, <table>, and <article> - Clearly defines its
content.
Semantic Elements in HTML
Many web sites contain HTML code like: <div id="nav"> <div class="header"> <div
id="footer"> to indicate navigation, header, and footer.
In HTML there are some semantic elements that can be used to define different parts of
a web page:
<article>
<aside>
<details>
<figcaption>
<figure>
<footer>
<header>
<main>
<mark>
<nav>
<section>
<summary>
<time>
Chapters
Introduction
News items
Contact information
A web page could normally be split into sections for introduction, content, and contact
information.
Example
<section>
<h1>WWF's Panda symbol</h1>
<p>The Panda has become the symbol of WWF. The well-known panda logo of WWF
originated from a panda named Chi Chi that was transferred from the Beijing Zoo to the
London Zoo in the same year of the establishment of WWF.</p>
</section>
An article should make sense on its own, and it should be possible to distribute it
independently from the rest of the web site.
Forum posts
Blog posts
User comments
Product cards
Newspaper articles
Example
<article>
<h2>Google Chrome</h2>
<p>Google Chrome is a web browser developed by Google, released in 2008. Chrome
is the world's most popular web browser today!</p>
</article>
<article>
<h2>Mozilla Firefox</h2>
<p>Mozilla Firefox is an open-source web browser developed by Mozilla. Firefox has
been the second most popular web browser since January, 2018.</p>
</article>
<article>
<h2>Microsoft Edge</h2>
<p>Microsoft Edge is a web browser developed by Microsoft, released in 2015.
Microsoft Edge replaced Internet Explorer.</p>
</article>
Example 2
<html>
<head>
<style>
.all-browsers {
margin: 0;
padding: 5px;
background-color: lightgray;
}
.browser {
background: white;
}
<article class="all-browsers">
<h1>Most Popular Browsers</h1>
<article class="browser">
<h2>Google Chrome</h2>
<p>Google Chrome is a web browser developed by Google, released in 2008.
Chrome is the world's most popular web browser today!</p>
</article>
<article class="browser">
<h2>Mozilla Firefox</h2>
<p>Mozilla Firefox is an open-source web browser developed by Mozilla. Firefox
has been the second most popular web browser since January, 2018.</p>
</article>
<article class="browser">
<h2>Microsoft Edge</h2>
<p>Microsoft Edge is a web browser developed by Microsoft, released in 2015.
Microsoft Edge replaced Internet Explorer.</p>
</article>
</article>
</body>
</html>
Can we use the definitions to decide how to nest those elements? No, we cannot!
So, you will find HTML pages with <section> elements containing <article> elements,
and <article> elements containing <section> elements.
Note: You can have several <header> elements in one HTML document.
However, <header> cannot be placed within a <footer>, <address> or
another <header> element.
Example
<article>
<header>
<h1>What Does WWF Do?</h1>
<p>WWF's mission:</p>
</header>
<p>WWF's mission is to stop the degradation of our planet's natural environment,
and build a future in which humans live in harmony with nature.</p>
</article>
authorship information
copyright information
contact information
sitemap
back to top links
related documents
Example
<footer>
<p>Author: Hege Refsnes</p>
<p><a href="mailto:[email protected]">[email protected]</a></p>
</footer>
Notice that NOT all links of a document should be inside a <nav> element.
The <nav> element is intended only for major blocks of navigation links.
Browsers, such as screen readers for disabled users, can use this element to determine
whether to omit the initial rendering of this content.
Example
<nav>
<a href="/html/">HTML</a> |
<a href="/css/">CSS</a> |
<a href="/js/">JavaScript</a> |
<a href="/jquery/">jQuery</a>
</nav>
The <aside> element defines some content aside from the content it is placed in (like a
sidebar).
Example
<p>My family and I visited The Epcot center this summer. The weather was nice, and
Epcot was amazing! I had a great summer together with my family!</p>
<aside>
<h4>Epcot Center</h4>
<p>Epcot is a theme park at Walt Disney World Resort featuring exciting attractions,
international pavilions, award-winning fireworks and seasonal special events.</p>
</aside>
Example 2
<html>
<head>
<style>
aside {
width: 30%;
padding-left: 15px;
margin-left: 15px;
float: right;
font-style: italic;
background-color: lightgray;
}
</style>
</head>
<body>
<p>My family and I visited The Epcot center this summer. The weather was nice, and
Epcot was amazing! I had a great summer together with my family!</p>
<aside>
<p>The Epcot center is a theme park at Walt Disney World Resort featuring exciting
attractions, international pavilions, award-winning fireworks and seasonal special
events.</p>
</aside>
<p>My family and I visited The Epcot center this summer. The weather was nice, and
Epcot was amazing! I had a great summer together with my family!</p>
<p>My family and I visited The Epcot center this summer. The weather was nice, and
Epcot was amazing! I had a great summer together with my family!</p>
</body>
</html>
HTML <figure> and <figcaption> Elements
The <figure> tag specifies self-contained content, like illustrations, diagrams, photos,
code listings, etc.
Example
<figure>
<img src="pic_trulli.jpg" alt="Trulli">
<figcaption>Fig1. - Trulli, Puglia, Italy.</figcaption>
</figure>
According to the W3C: "A semantic Web allows data to be shared and reused across
applications, enterprises, and communities."
Tag Description
<details> Defines additional details that the user can view or hide
<figure> Specifies self-contained content, like illustrations, diagrams, photos, code listings,
etc.
For a complete list of all available HTML tags, visit our HTML Tag Reference.
PHP Operators
PHP Operator is a symbol i.e used to perform operations on operands. In simple words,
operators are used to perform operations on variables or values. For example:
In the above example, + is the binary + operator, 10 and 20 are operands and $num is
variable.
o Arithmetic Operators
o Assignment Operators
o Bitwise Operators
o Comparison Operators
o Incrementing/Decrementing Operators
o Logical Operators
o String Operators
o Array Operators
o Type Operators
o Execution Operators
o Error Control Operators
Arithmetic Operators
The PHP arithmetic operators are used to perform common arithmetic operations such as
addition, subtraction, etc. with numeric values.
Assignment Operators
The assignment operators are used to assign value to different variables. The basic
assignment operator is "=".
Bitwise Operators
The bitwise operators are used to perform bit-level operations on operands. These
operators allow the evaluation and manipulation of specific bits within the integer.
& And $a & $b Bits that are 1 in both $a and $b are set to 1, otherwise 0.
~ Not ~$a Bits that are 1 set to 0 and bits that are 0 are set to 1
<< Shift left $a << $b Left shift the bits of operand $a $b steps
>> Shift right $a >> $b Right shift the bits of $a operand by $b number of places
Comparison Operators
Comparison operators allow comparing two values, such as number or string. Below the
list of comparison operators are given:
Operator Name Example Explanation
=== Identical $a === $b Return TRUE if $a is equal to $b, and they are of same
data type
!== Not identical $a !== $b Return TRUE if $a is not equal to $b, and they are not of
same data type
<= Less than or equal $a <= $b Return TRUE if $a is less than or equal $b
to
Incrementing/Decrementing Operators
The increment and decrement operators are used to increase and decrease the value of a
variable.
Logical Operators
The logical operators are used to perform bit-level operations on operands. These
operators allow the evaluation and manipulation of specific bits within the integer.
xor Xor $a xor $b Return TRUE if either $ or $b is true but not both
String Operators
The string operators are used to perform the operation on strings. There are two string
operators in PHP, which are given below:
Operator Name Example Explanation
Array Operators
The array operators are used in case of array. Basically, these operators are used to
compare the values of arrays.
=== Identity $a === $b Return TRUE if $a and $b have same key/value pair of same
type in same order
Type Operators
The type operator instanceof is used to determine whether an object, its parent and its
derived class are the same type or not. Basically, this operator determines which certain
class the object belongs to. It is used in object-oriented programming.
<?php
//class declaration
class Developer
{}
class Programmer
{}
//creating an object of type Developer
$charu = new Developer();
Output:
Charu is a developer.
bool(true) bool(false)
Execution Operators
PHP has an execution operator backticks (``). PHP executes the content of backticks as
a shell command. Execution operator and shell_exec() give the same result.
PHP has one error control operator, i.e., at (@) symbol. Whenever it is used with an
expression, any error message will be ignored that might be generated by that expression.
[ array() left
** arithmetic right
| bitwise OR left
|| logical OR left
?: ternary left
or logical left
, many uses (comma) left
The var_dump() function dumps information about one or more variables. The
information holds type and value of the variable(s).
Syntax
var_dump(var1, var2, ...);
Parameter Values
Parameter Description
var1, var2, ... Required. Specifies the variable(s) to dump information from
Technical Details
Return Type: -
Example
<?php
$a = 32;
echo var_dump($a) . "<br>";
$b = "Hello world!";
echo var_dump($b) . "<br>";
$c = 32.5;
echo var_dump($c) . "<br>";
Q5) a) What are selectors in CSS? Explain with suitable example. [4]
CSS selectors are used to select the content you want to style. Selectors are the
part of CSS rule set. CSS selectors select HTML elements according to its id,
class, type, attribute etc.
<!DOCTYPE html>
<html>
<head>
<style>
p{
text-align: center;
color: blue;
}
</style>
</head>
<body>
<p>This style will be applied on every paragraph.</p>
<p id="para1">Me too!</p>
<p>And me!</p>
</body>
</html>
Output:
Me too!
And me!
2) CSS Id Selector
The id selector selects the id attribute of an HTML element to select a specific element.
An id is always unique within the page so it is chosen to select a single, unique element.
It is written with the hash character (#), followed by the id of the element.
<!DOCTYPE html>
<html>
<head>
<style>
#para1 {
text-align: center;
color: blue;
}
</style>
</head>
<body>
<p id="para1">Hello DYP.com</p>
<p>This paragraph will not be affected.</p>
</body>
</html>
Output:
Hello DYP.com
The class selector selects HTML elements with a specific class attribute. It is used with
a period character . (full stop symbol) followed by the class name.
<!DOCTYPE html>
<html>
<head>
<style>
.center {
text-align: center;
color: blue;
}
</style>
</head>
<body>
<h1 class="center">This heading is blue and center-aligned.</h1>
<p class="center">This paragraph is blue and center-aligned.</p>
</body>
</html>
Output:
This heading is blue and center-aligned.
If you want to specify that only one specific HTML element should be affected then you
should use the element name with class selector.
<!DOCTYPE html>
<html>
<head>
<style>
p.center {
text-align: center;
color: blue;
}
</style>
</head>
<body>
<h1 class="center">This heading is not affected</h1>
<p class="center">This paragraph is blue and center-aligned.</p>
</body>
</html>
Output:
The universal selector is used as a wildcard character. It selects all the elements on the
pages.
<!DOCTYPE html>
<html>
<head>
<style>
*{
color: green;
font-size: 20px;
}
</style>
</head>
<body>
<h2>This is heading</h2>
<p>This style will be applied on every paragraph.</p>
<p id="para1">Me too!</p>
<p>And me!</p>
</body>
</html>
Output:
This is heading
Me too!
And me!
The grouping selector is used to select all the elements with the same style definitions.
Grouping selector is used to minimize the code. Commas are used to separate each
selector in grouping.
h1 {
text-align: center;
color: blue;
}
h2 {
text-align: center;
color: blue;
}
p{
text-align: center;
color: blue;
}
As you can see, you need to define CSS properties for all the elements. It can be grouped
in following ways:
h1,h2,p {
text-align: center;
color: blue;
}
<!DOCTYPE html>
<html>
<head>
<style>
h1, h2, p {
text-align: center;
color: blue;
}
</style>
</head>
<body>
<h1>Hello DYP.com</h1>
<h2>Hello DYP.com (In smaller font)</h2>
<p>This is a paragraph.</p>
</body>
</html>
CSS frameworks are tools that UI designers use to make their work easier. Instead of
starting from scratch, frameworks allow developers to swiftly create user interfaces that
can be changed and iterated throughout a project. The basic purpose of the CSS
framework is to bring a more standardized practice for web development. They're
helpful for larger projects, bigger teams, and those who need to design a theme that can
be used on multiple projects.
CSS framework is a set of prepared and ready-to-use CSS stylesheets. They're designed
for typical tasks like putting up navbars and are frequently enhanced with other
technologies like SASS and JavaScript. CSS frameworks provide more than just time
savings. Frameworks deliver standards to teams with multiple developers, especially
larger ones. Frameworks standardize layouts and allow one developer to readily
comprehend another developer’s code, rather than each developer writing the code by
himself from the beginning for each project, making their work hectic and tedious. This
saves time and ensures a smoother development cycle with fewer defects and improved
team communication.
CSS Framework
There are numerous CSS frameworks available, and all of them are incredibly
beneficial. Though it is difficult to select a good framework from the several available
options, here are a few common and popular frameworks you can choose from.
1. Bootstrap
Bootstrap has a very nice responsive design, due to which it is regarded as one of the
best CSS frameworks. It was created by Twitter and first launched in 2011.
Bootstrap is a powerful front-end framework for building modern web pages and web
applications. It is open-source and free to use. However, it comes with many HTML
and CSS templates for UI elements like buttons and forms. Bootstrap also supports
JavaScript extensions. Bootstrap uses SASS variables and mixins for theming, a
responsive grid system for layout, pre-built components for design patterns, and JS
plugins for user interaction.
Advantages of Bootstrap
LESS and SASS are two of the most common preprocessors used in Bootstrap's
code.
It is a good framework in terms of usage and popularity, and it saves a lot of time. It
has a relatively short learning curve.
Disadvantages of Bootstrap
The web pages or front-ends created with Bootstrap seem very similar, and
Bootstrap's flexibility is limited.
Due to the vast number of modules loaded in Bootstrap, CSS projects have a large
build size. We can't pick and choose whatever components we want; we will have to
change the codebase at our own risk to get rid of them.
Bootstrap 4 is the most recent version of the Bootstrap framework. It became the first
choice for developers because it has new SASS variables for global styling and easy
theming, bringing new dimensions for developers in building projects.
Except for Internet Explorer 9 and below, Bootstrap 4 is compatible with all major
browsers. To support these older browsers, tests are being performed so that these
features can be easily implemented in more devices.
2. Tailwind CSS
Tailwind CSS is a utility-first CSS framework that differs from other top CSS
frameworks like Bulma and Bootstrap. Tailwind CSS provides pre-designed
components that may be used as a foundation for subsequent development. It does not
come with a pre-made design, but it allows us to include our own personal style rapidly.
With Tailwind CSS, we can use libraries like Purge CSS to reduce the CSS build
size substantially.
Disadvantages of Tailwind
Because there are so many classes for styling, readability can be a problem for
certain developers.
3. Foundation
Another excellent CSS framework is Foundation. HTML, CSS, SASS, and Javascript
are part of this powerful front-end CSS framework. It is best suited for large web
applications that require a design host. It was built with a mobile-first approach and is
very responsive. It is often called “The most advanced responsive front-end framework
in the world.”
Advantages of Foundation
Disadvantages of Foundation
It has several features and is more complex than other frameworks. It provides a lot
of versatility when it comes to developing front-end templates.
4. Bulma
Bulma is another great flexbox-based CSS framework. It's an open-source CSS library
that is 100 percent responsive and comes with several pre-configured components.
Bulma creates Metro-style grids with a method called tiles, which makes the website
look sleek and smooth. It has a lightweight framework that allows us to import only the
elements we need for our current web design.
Advantages of Bulma
It is a framework independent of the environment and sits on top of the logic layer.
Disadvantages of Bulma
Frameworks for CSS are fantastic. They help us to get off to a good start when building
a new site by providing structured code that ensures our site is responsive, solid, and
practical with no work.
In the modern era, with increasing digitalization, everyone wants to ensure their
presence on the internet, which has led to the development of many websites with a lot
of pages. Using a pre-built framework or structure can help us with the day-to-day labor
of website architecture. So while choosing a framework, we must keep certain points in
consideration, as discussed in the next section:
To begin, we must have some knowledge of our website. Is it even necessary to have a
system? Structures are beneficial to most locations with a large number of pages. The
ideal amount of pages can change, but if we find ourselves repeating the same HTML,
CSS, or even JavaScript on one of our pages, a layout or structure can help.
Framework Language
We should be familiar with the computer language(s) that our framework employs. As
previously stated, some simple frameworks are nothing more than basic HTML
templates, while more complicated frameworks may include CSS and JavaScript. Some
frameworks construct the CSS using LESS or SASS, while others utilize Ruby or other
computer languages to compile the pages once they're built. It will be challenging to
build our framework if we are unfamiliar with the language(s) it employs.
Framework Features
The CSS framework has a standard set of grids, selectors, and other code. It limits
what we can design.
If we're already comfortable and effective with one method of designing and
programming and are compelled to use a CSS framework we're unfamiliar with, we
may end up wasting time.
We will inevitably find code in a CSS framework that we don't need. It's quite
improbable that we'll use all of a framework's features. As a result, we're stuck with
superfluous code.
b) Write a PHP script & insert at least 5 records into it & update specific record
in database. Assume student table with required fields in database. [6]
You already solved this question in practical lab.