web_technology
web_technology
WEB TECHNOLOGY II
1.Define CSS. Explain its types i.e. Inline, Internal and External CSS with example.
CSS stands for Cascading Style Sheets which consists of various styles that defines how to display HTML
elements. It is used to make the design of the Website dynamic and attractive. Styles are normally stored
in Style Sheets. Since, every tags cannot design the Web site in very fascinating way we use CSS to
solve that problem.
</BODY>
</HTML>
Above HTML file will generate empty webpage with just red color background. Same thing
can be done by using several types of CSS i.e inline, internal and external CSS.
Inline CSS
This types of CSS are written inside the HTML tag.
<HTML>
<HEAD><TITLE>Inline CSS</TITLE></HEAD>
<BODY style = “background-color: red;”>
</BODY>
</HTML>
In above HTML file we have added style inside BODY tag. Similarly, we can add any number
of CSS inside HTML tag.
Internal CSS
This types of CSS are written inside <STYLE> tag, which is placed in -between HEAD tag of
an HTML document.
<HTML>
<HEAD><TITLE>Internal CSS</TITLE>
<STYLE>
body{
background-color: red;
}
</STYLE>
</HEAD>
<BODY>
</BODY>
</HTML>
In above HTML file we have added STYLE tag inside HEAD. CSS is written directly selecting
body tag.
Note: We can select id as well as class of any HTML tag. # is used to access id of the tag
whereas, . is used to access class of the tag.
External CSS
In this type we have to prepare HTML file and CSS file separately. These two file are linked by
following statement.
<HTML>
<HEAD><TITLE>External CSS</TITLE>
<link rel=“stylesheet” href=“sukuna.css”>
</HEAD>
<BODY>
</BODY>
</HTML>
Since we have linked “mero.css” in HTML file we have to create a separate CSS file named
“sukuna.css”. We can directly right CSS without STYLE tag in CSS document.
body{
background-color: red;
}
2. Demonstrate the external CSS implemented in the Web page.
CSS stands for Cascading Style sheets. CSS can control the layout of the multiple webpage all at once.
There are three types of CSS, Inline CSS, Internal CSS and External CSS.
External CSS contains separate CSS file which contains only style property with the help of tag attributes.
The separate CSS file should be linked with the HTML document using <link> tag.
For example:
HTML file (index.html)
<html>
<head>
<title>external CSS</title>
<link rel="stylesheet" href="external.CSS">
</head>
<body>
<p>Sukuna</p>
</body>
</html>
CSS file (external.CSS)
p{ color: Blue;
font-size: 30px;
JavaScript is a client-side scripting language used for web development along with other front-end
development tool such as HTML and CSS. JavaScript helps to give dynamic behavior to our web pages such
as adding animation, drop down menus, client-side validation etc. More over JS can be used for mobile apps
development and game development. JavaScript is known as scripting language because it does not need to
be compiled before execution, it executes in run-time environment through web browser.
<HTML>
<HEAD><TITLE>Sample</TITLE></HEAD>
<BODY>
<BUTTON onclick = “alert(‘Your message’)”>Click here</BUTTON>
</BODY>
</HTML>
Here, we have added alert message through onclick event. When user press the Click me button then alert
message will be shown in the web browser.
This is the method of adding JS code within the HTML document. JS code is added internally with in the
script tag inside body of the HTML document. JavaScript code can be embedded within HTML document
as follows:
<HTML>
<HEAD><TITLE>js</TITLE></HEAD>
<BODY>
<BUTTON onclick = “sukuna( )”>Click here</BUTTON>
<SCRIPT>
function sukuna( )
{
alert(“Your message”);
}
</SCRIPT>
</BODY>
</HTML>
Here, we have created a JS function named sukuna( ), this function is called when user press the Click me
button. Once button is pressed alert message is displayed which is defined inside function within Script tag.
This is the most popular methods of adding JS in our web pages. To add external JavaScript we have to
create separate JS file which is linked with our HTML document as:
<HTML>
<HEAD><TITLE>Sample</TITLE></HEAD>
<SCRIPT src = “hello.js”></Script>
<BODY>
<BUTTON onclick = “sukuna( )”>Click here</BUTTON>
</BODY>
</HTML>
Also create a JS file with .js extension and add following code
function sukuna( )
{
alert(“Your message”);
}
Here, we have created separate HTML and JS file in same location. Since, we have linked our JS file with
our HTML document, every code which is written in JS file will be implemented on HTML document.
<html>
<head>
<title>Sum</title>
</head>
<body>
<script>
var x=5;
var y=10;
function sum()
{
var sum=x+y;
document.write("The sum of "+x+" and "+y+" is "+ sum);
}
sum(); //calling JavaScript function
</script>
</body>
</html>
Output: The sum of 5 and 10 is 15
Java script provides different data types to hold different types of values. There are two types of data
types in JavaScript. a) Primitive data type
b) Non-primitive data type
It has two operators, the "?" (Question mark) and ":" (Colon), which separates the condition from the
result. If the condition is true, it will run and gives the first expression as result and it the condition
is false, it runs and gives the second expression as result.
e) Assignment Operators
Assignment operator is a symbol used to assign a value or a result of an expression to an identifier.
Some assignment operators are (=,+=,-=,%=,&=).
The JavaScript loops are used to iterate or repeat the execution of code using for, while, do-while loop.
There are three types of loops in JavaScript.
a) for loop :for loop is used when the number of repetition are known. It consists of three expressions.
Initialization, condition and increment/decrement are the three expressions of for loop.
For eg. JavaScript program to display the first 5 natural numbers using for loop.
<script>
var i;
for(i=1;i<=5;i++)
{
document.write(i );
}
</script>
Output: 1 2 3 4 5
b) while loop: while loop is used when the number of repetition in unknown. It consists only one
expression i.e. condition. Once condition becomes false, the loop will be terminated.
For eg. JavaScript program to display the first 5 natural numbers using while loop.
<script>
var i=1;
while(i<=5)
{
document.write(i);
i++;
}
</script>
Output:
12345
c) do-while loop do-while is similar to the while loop. The only difference is, it checks the condition
at the end of the loop. This means that the loop will always be executed at least once.
For eg. JavaScript program to display the first 5 natural numbers using do-while loop.
<script>
var i=1;
do
{
document.write(i);
i++;
}while(i<=5);
</script>
Output:
12345
A variable is an identifier whose value may change during the execution of the program. It is simply a
name of storage location. There are two types of variables in JavaScript:
a. Local variable
A JavaScript local variable is declared inside the block of function. It is accessible within the function
or block only. For example:
<script>
function sum()
{
var x=5; //local variable
var y=10; //local variable
var sum=x+y;
document.write("The sum of "+x+" and "+y+" is "+ sum);
}
sum(); //calling JavaScript function
</script>
b. Global variable
A JavaScript variable is accessible from any function. A variable i.e, declared outside function or
declared with a window object is known as a global variable.
For example: <script>
var x=5; //global variable
var y=10; //global variable
function sum()
{
var sum=x+y;
document.write("The sum of "+x+" and "+y+" is "+ sum);
}
sum(); //calling JavaScript function
</script>
JavaScript's interaction with HTML is handled through events that occurs when the user or the browser
manipulates a page. When the page loads, it is called an event. When the user clicks button, that clicks
to an event. Other examples include events like pressing any key, closing window, resizing a window.
Developers can use these events to execute JavaScript coded responses, which cause buttons to close
windows, message to be displayed to users, data to be validated, and virtually any other types of
response imaginable. Some events are onclick, onsubmit, onmouseover and onmouseout, onfocus and
onblur,etc.
For example:
<html>
<head>
<script>
function sayHello()
{
alert("Hello world");
}
</script
</head>
<body>
<p> click the button below to see the result</p>
<button onclick="sayHello()">click</button>
</body>
</html>
12. Write a function to check whether the given number is odd or even using JavaScript.
<html>
<head>
<title>check odd or even</title>
</head>
<body>
<script>
function check()
{
var n=parseInt(prompt("Enter a number"));
if(n%2==0)
alert("Even number");
else
alert("Odd number");
}
check(); //calling Java Script function
</script>
</body>
</html>
Output
Enter a number 4
Even number
14. Write a JavaScript program to calculate the simple interest using principle, time and rate.
<html>
<head>
<title>simple interest</title>
</head>
<body>
<script>
function si ()
{
var p=parseInt(prompt("enter principle"));
var t=parseInt(prompt("enter time"));
var r=parseInt(prompt("enter rate"));
var si=(p*t*r)/100;
alert("The simple interest is "+si);
}
si(); //calling JavaScript function
</script>
</body>
</html>
The comparisons between client-side scripting and server-side scripting are given below:
Client-side scripting
• It is a scripting that run on a client end – web browser.
• It deals with the user interface and lighter functionality.
• Response from a client-side script is faster.
• It cannot connect to the databases on the web server.
• Examples of client-side scripting languages: JavaScript, VB Script, etc
Server side scripting
• It is normally used to handle browser requests.
• The server executes the script and returns to the browser.
• Response form a server-side script is slower because the scripts are processed remotely.
• Server-side scripting is used to connect to the database that is on web server.
• Example of server-side scripting languages: PHP, JSP, Asp.Net, ASP etc.