HTML & JavaScript - Practice Questions PDF
HTML & JavaScript - Practice Questions PDF
HTML & JavaScript - Practice Questions PDF
com
HTML & JavaScript Practice Questions
i
Evincepub Publishing
Mansarover Park, West Delhi, India 110015
SMIG - 65, Parijat Extension, Bilaspur, Chhattisgarh 495001
This book has been published with all reasonable efforts taken
to make the material error-free after the consent of the author.
No part of this book shall be used, reproduced in any manner
whatsoever without written permission from the author, except
in the case of brief quotations embodied in critical articles and
reviews. The Author of this book is solely responsible and
liable for its content including but not limited to the views,
representations, descriptions, statements, information,
opinions and references [“Content”]. The Content of this book
shall not constitute or be construed or deemed to reflect the
opinion or expression of the Publisher or Editor. Neither the
Publisher nor Editor endorse or approve the Content of this
book or guarantee the reliability, accuracy or completeness of
the Content published herein and do not make any
representations or warranties of any kind, express or implied,
including but not limited to the implied warranties of
merchantability, fitness for a particular purpose. The Publisher
and Editor shall not be liable whatsoever for any errors,
omissions, whether such errors or omissions result from
negligence, accident, or any other cause or claims for loss or
damages of any kind, including without limitation, indirect or
consequential loss or damage arising out of use, inability to
use, or about the reliability, accuracy or sufficiency of the
information contained in this book.
ii
www.ebook3000.com
HTML & JavaScript
Practice Questions
By
Dheeraj Singh
iii
About the Book
iv
www.ebook3000.com
About the Author
Dheeraj Singh, an enthusiastic student
and teacher, loves computers and
programming languages like HTML,
JavaScript, C, C++ and Java. He is
having the post graduation degree on
Economics. Despite of getting a degree in
Economics, he is always found surrounded by
computers. He is currently running his own tutorials
on Programming Languages online. He has written
this book at an early age of 20. The main aim of
Dheeraj to write this book is to clear the small and
necessary doubts of students willing to start
programming in HTML and JavaScript.
v
Content List
HTML
attributes.
vi
www.ebook3000.com
Write a program to implement inline css.
8.
Write a program to implement internal css.
9.
write a program to implement external css.
10.
JAVA SCRIPT
vii
Write a JavaScript program to compute the greatest
23.
25.
viii
www.ebook3000.com
27. Write a program to Retrieves values from cookie.
30. method.
31. or odd.
ix
Dheeraj Singh
<HEAD>
</HEAD>
</marquee>
</marquee> </font>
<marquee behavior="alternate">
<h1><----Alternate Brhavior---></h1>
</marquee>
</BODY> </HTML>
1
HTML & JavaScript Practice Questions
Coding Output
www.ebook3000.com
Dheeraj Singh
<HEAD>
</HEAD>
<BODY>
<BR>
<tr>
<th>DAY</th>
<th>12:00-2:00</th>
<th>2:00-2:45</th>
<th>2:45-3:15</th>
<th>3:15-4:30</th>
3
HTML & JavaScript Practice Questions
<th>4:30-5:00</th>
</tr>
<tr>
<td>MONDAY</td>
<td>TOC</td>
<td>POS</td>
<td>WT</td>
<td>DM</td>
</tr>
<tr>
<td>TUESDAY</td>
<td>TOC</td>
<td>OOP</td>
<td>WT</td>
<td>DM</td>
</tr>
www.ebook3000.com
Dheeraj Singh
<tr>
<td>WEDNESDAY</td>
<td>POS</td>
<td>OOP</td>
<td>WT</td>
<td>DM</td>
</tr>
<tr>
<td>THURSDAY</td>
<td>-</td>
<td>POS</td>
<td>OOP</td>
<td>TOC</td>
<td>DM</td>
</tr>
<tr>
5
HTML & JavaScript Practice Questions
<td>FRIDAY</td>
<td>POS</td>
<td>OOP</td>
<td>TOC</td>
<td>WT</td>
</tr>
</TABLE>
</BODY>
</HTML>
www.ebook3000.com
Dheeraj Singh
Coding Output
7
HTML & JavaScript Practice Questions
<HEAD>
<TITLE>FORM EXAMPLE</TITLE>
</HEAD>
<BODY>
<FORM>
<center>
EMPLOYEE NAME :
<br><br>
FATHER'S NAME :
<br><br>
GENDER :
www.ebook3000.com
Dheeraj Singh
<br><br>
Department :
<select name=department>
<option value="msc">SALES</option>
<option
value="mca">ACCOUNT</option>
</select>
<br><br>
HOBBY :
<br><br>
9
HTML & JavaScript Practice Questions
ADDRESS :
</textarea>
<br><br>
CREATE PASSWORD :
<br><br>
</center>
</FORM>
</BODY>
</HTML>
10
www.ebook3000.com
Dheeraj Singh
Coding Output
11
HTML & JavaScript Practice Questions
<HEAD>
<TITLE>IMG EXAMPLE</TITLE>
</HEAD>
<BODY>
<center>
<H2>image example</H2>
</center>
</BODY>
</HTML>
12
www.ebook3000.com
Dheeraj Singh
Coding Output
13
HTML & JavaScript Practice Questions
<HEAD>
</HEAD>
<BODY>
<center>
<H2>
SUBSCRIPT : H<sub>2</sub>O =
H<sub>2</sub> + O
<br><br>
SUPERSCRIPT : 2<sup>4</sup> = 16
</H2>
</center>
</BODY>
</HTML>
14
www.ebook3000.com
Dheeraj Singh
Coding Output
15
HTML & JavaScript Practice Questions
<HEAD>
<TITLE>Frame Test...</TITLE></HEAD>
<FRAMESET COLS="30%,70%">
<FRAMESET ROWS="75%,25%">
</FRAMESET>
<FRAMESET ROWS="*">
</FRAMESET>
</FRAMESET>
</HEAD>
</HTML>
16
www.ebook3000.com
Dheeraj Singh
<HEAD>
<TITLE>SVG EXAMPLE</TITLE>
</HEAD>
<BODY>
<polygon
points="100,10,40,180,190,60,10,60,160,180"
style="fill:lime;stroke:purple;stroke-width:5;fill-
rule:evenodd;" />
</svg>
</BODY>
</HTML>
17
HTML & JavaScript Practice Questions
Coding Output
18
www.ebook3000.com
Dheeraj Singh
<HEAD>
<TITLE>CSS EXAMPLE</TITLE>
</HEAD>
<BODY>
<h1 style="background-color:#d0e4fe;font-
size:100px;"/>
Inline CSS
</h1>
</BODY>
</HTML>
19
HTML & JavaScript Practice Questions
Coding Output
20
www.ebook3000.com
Dheeraj Singh
<HEAD>
<TITLE>CSS EXAMPLE</TITLE>
<style>
h1
font-size: 100px;
background-color: yellow;
</style>
</HEAD>
<BODY>
<h1>
Internal CSS
</h1> </BODY>
</HTML>
21
HTML & JavaScript Practice Questions
Coding Output
22
www.ebook3000.com
Dheeraj Singh
<HEAD>
<TITLE>CSS EXAMPLE</TITLE>
</HEAD>
<BODY>
<h1>
External CSS
</h1>
</BODY>
</HTML>
extrnal.css
background-color: #d0e4fe;
font-style:italic; }
23
HTML & JavaScript Practice Questions
Coding Output
24
www.ebook3000.com
Dheeraj Singh
<HEAD>
<TITLE>Predefined Functions</TITLE>
</HEAD>
<BODY>
<script>
alert("CONTINUE....?");
var txt="";
if(b) document.write("<h1>Welcome
"+name+"</h1>");
else document.write("<h1>Input is
cacelled!!!!</h1>")
</script>
</BODY>
25
HTML & JavaScript Practice Questions
Coding Output
26
www.ebook3000.com
Dheeraj Singh
<HEAD>
<TITLE>Predefined Functions</TITLE>
<script>
function fun()
var n = document.getElementById("n").value;
fact(n);
var f=1;
function fact(n)
if(n>0)
f = f*n;
fact(n-1);
27
HTML & JavaScript Practice Questions
else
document.getElementById("result").innerHTML =
"Factorial = "+f;
</script>
</HEAD>
<BODY>
<br><br>
<br><br>
<h2 id="result"></h2>
</BODY>
</HTML>
28
www.ebook3000.com
Dheeraj Singh
Coding Output
29
HTML & JavaScript Practice Questions
<HEAD>
<TITLE>Predefined Functions</TITLE>
<script>
function fun()
var n = document.getElementById("n").value;
document.getElementById("result").innerHTML =
"Result = "+n*n*n;
</script>
</HEAD>
<BODY>
<br><br>
30
www.ebook3000.com
Dheeraj Singh
<br><br>
<h2 id="result"></h2>
</BODY>
</HTML>
31
HTML & JavaScript Practice Questions
Coding Output
32
www.ebook3000.com
Dheeraj Singh
<HEAD>
<TITLE>Predefined Functions</TITLE>
<script>
function fun()
var n = document.getElementById("n").value;
document.getElementById("result").innerHTML
= "Result = "+r+" Fahrenheit";
</script>
</HEAD>
<BODY>
<br><br>
33
HTML & JavaScript Practice Questions
<br><br>
<h2 id="result"></h2>
</BODY>
</HTML>
34
www.ebook3000.com
Dheeraj Singh
Coding Output
35
HTML & JavaScript Practice Questions
36
www.ebook3000.com
Dheeraj Singh
<HEAD>
<TITLE>Predefined Functions</TITLE>
</HEAD> <BODY>
<script>
</script>
</BODY>
</HTML>
37
HTML & JavaScript Practice Questions
Coding Output
38
www.ebook3000.com
Dheeraj Singh
<HEAD>
<TITLE>Armstrong Numbers</TITLE>
</HEAD>
<BODY>
<script>
var i;
document.write("<h2>Armstrong Numbers");
for(i=1;i<=999;i++)
if(Math.floor(i/100) == Math.floor(i%10))
if(Math.floor(i/100)==0)
39
HTML & JavaScript Practice Questions
document.write("<br>0"+i);
else document.write("<br>"+i);
</script>
</BODY>
</HTML>
40
www.ebook3000.com
Dheeraj Singh
Coding Output
41
HTML & JavaScript Practice Questions
<HEAD>
<TITLE>Pattern</TITLE>
</HEAD>
<BODY>
<script>
var i,j;
document.write("<h2>Pattern:<br>");
for(i=0;i<10;i++)
for(j=0;j<=i;j++)
document.write(" *");
document.write("<br>");
</script>
42
www.ebook3000.com
Dheeraj Singh
</BODY>
</HTML>
Coding Output
43
HTML & JavaScript Practice Questions
<HEAD>
<TITLE>Pattern</TITLE>
<script>
function gcd()
var x = document.getElementById("x").value;
var y = document.getElementById("y").value;
var hcf=1;
if(x<y)
var t = x;
x = y;
y = t;
44
www.ebook3000.com
Dheeraj Singh
while(hcf!=0)
hcf = x%y;
x = y;
y = hcf;
document.getElementById("result").innerHTML
= "GCD = "+x;
</script>
</HEAD>
<BODY>
<h2>
</h2>
45
HTML & JavaScript Practice Questions
<br><br>
<br><br>
<h2 id="result"></h2>
</BODY>
</HTML>
46
www.ebook3000.com
Dheeraj Singh
Coding Output
47
HTML & JavaScript Practice Questions
<HEAD>
<TITLE>Pattern</TITLE>
<script>
function convert()
var n =
document.getElementById("x").value;
var a = 0;
if(document.getElementById("1").checked)
a=1;
else
if(document.getElementById("2").checked)
a=2;
else
if(document.getElementById("3").checked)
48
www.ebook3000.com
Dheeraj Singh
a=3;
switch(a)
case 1:
var x=0,i=0;
while(n>0)
x = x + n%2*Math.pow(10,i);
n = Math.floor(n/2);
i++;
document.getElementById("result").innerHTML =
"Binary value : "+x;
break;
case 2:
var x=0,i=0;
while(n>0)
49
HTML & JavaScript Practice Questions
x = x + n%16*Math.pow(10,i);
n = Math.floor(n/16);
i++;
document.getElementById("result").innerHTML =
"Hexadecimal value : "+x;
break;
case 3:
var x=0,i=0;
while(n>0)
x = x + n%8*Math.pow(10,i);
n = Math.floor(n/8);
i++;
document.getElementById("result").innerHTML =
"Octal value : "+x;
50
www.ebook3000.com
Dheeraj Singh
break;
default:
document.getElementById("result").innerHTML =
"Please select converter type";
</script>
</HEAD>
<BODY>
<p>
<br><br>
</p>
51
HTML & JavaScript Practice Questions
<br>
<br><br>
<h2 id="result"></h2>
</BODY>
</HTML>
52
www.ebook3000.com
Dheeraj Singh
Coding Output
53
HTML & JavaScript Practice Questions
<HEAD>
<TITLE>Array</TITLE>
</HEAD>
<BODY>
<script>
var a=1,c=0,item=arr[0],i,j;
for(i=0;i<arr.length;i++)
for(j=i;j<arr.length;j++)
if(arr[i]==arr[j]) c++;
if(c>a)
54
www.ebook3000.com
Dheeraj Singh
item = arr[i];
a = c;
c=0;
</script>
</BODY>
</HTML>
55
HTML & JavaScript Practice Questions
Coding Output
56
www.ebook3000.com
Dheeraj Singh
<HEAD>
<TITLE>Date</TITLE>
<script>
function getdays()
var m =
document.getElementById("m").value;
var y = document.getElementById("y").value;
document.getElementById("result").innerHTML =
day+" Days";
</script>
</HEAD>
<BODY>
57
HTML & JavaScript Practice Questions
<p>
Month :
<br><br>
Year :
<br><br>
<br>
<h2 id="result"></h2>
</p>
</BODY>
</HTML>
58
www.ebook3000.com
Dheeraj Singh
Coding Output
59
HTML & JavaScript Practice Questions
<HEAD>
<TITLE>Date</TITLE>
<script>
function add()
var m =
document.getElementById("m").value;
someDate.setMinutes(someDate.getMinutes()+m);
document.getElementById("result").innerHTML =
"Minutes "+someDate.getMinutes();
</script>
</HEAD>
60
www.ebook3000.com
Dheeraj Singh
<BODY>
<p>
Minutes to add :
<br><br>
<br>
<h2 id="result"></h2>
</p>
</BODY>
</HTML>
61
HTML & JavaScript Practice Questions
Coding Output
62
www.ebook3000.com
Dheeraj Singh
<head>
<script language="JavaScript">
function keyDown(){
alert("key pressed");
function keyUp(){
alert("key released");
function keypress(){
</script>
</head>
<body>
63
HTML & JavaScript Practice Questions
</body>
</html>
64
www.ebook3000.com
Dheeraj Singh
Coding Output
65
HTML & JavaScript Practice Questions
<head></head>
<body>
</div>
<script language="JavaScript">
function whichbutton(event){
</script>
</body>
</html>
66
www.ebook3000.com
Dheeraj Singh
Coding Output
67
HTML & JavaScript Practice Questions
<html>
<head>
<script language="JavaScript">
function load(){
alert("onload webpage");
function unload(){
alert("unload a webpage");
</script></head>
<body Onload="load()"
Onunload="unload()">
</body>
</html>
68
www.ebook3000.com
Dheeraj Singh
Coding Output
69
HTML & JavaScript Practice Questions
<head>
</head>
<body>
<hr />
<script type="text/javascript">
70
www.ebook3000.com
Dheeraj Singh
document.cookie = final_cookie;
alert(final_cookie);
//]]>
</script>
</body>
</html>
71
HTML & JavaScript Practice Questions
Coding Output
72
www.ebook3000.com
Dheeraj Singh
<head>
</head>
<body>
<hr />
<script type="text/javascript">
if (document.cookie.length > 0)
offset = document.cookie.indexOf(search_cookie)
73
HTML & JavaScript Practice Questions
if (offset != -1)
offset += search_cookie.length
end = document.cookie.indexOf(";",offset)
if (end == -1)
end = document.cookie.length
alert(decodeURIComponent(document.cookie.substring(
offset, end)))
//]]>
</script>
</head>
</body>
</html>
74
www.ebook3000.com
Dheeraj Singh
Coding Output
75
HTML & JavaScript Practice Questions
<HEAD>
<TITLE>FORM EXAMPLE</TITLE>
<script>
function validation()
var
x=document.forms["myForm"]["sname"].value;
if(x==null||x=="")
x=
document.forms["myForm"]["fname"].value;
if(!document.getElementById("m").checked ||
!document.getElementById("f").checked)
76
www.ebook3000.com
Dheeraj Singh
//Email Validation
x=document.forms["myForm"]["email"].value;
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 ||
dotpos+2>=x.length)
return false;
var len
=document.forms["myForm"]["pwd"].length;
</script>
</HEAD>
<BODY>
<FORM name="myForm">
77
HTML & JavaScript Practice Questions
<H2 align="center">STUDENT
REGISTRATION</H2>
<center>
STUDENT NAME :
<br><br>
FATHER'S NAME :
<br><br>
GENDER :
<br><br>
COURSE :
<select name=course>
<option value="msc">MSC</option>
<option value="mca">MCA</option>
78
www.ebook3000.com
Dheeraj Singh
</select>
<br><br>
HOBBY :
<br><br>
Email Address :
</textarea>
<br><br>
CREATE PASSWORD :
<br><br>
</center>
</FORM>
</BODY>
</HTML>
80
www.ebook3000.com
Dheeraj Singh
Coding Output
81
HTML & JavaScript Practice Questions
<HEAD>
<TITLE>Clock</TITLE>
<script>
function startTime()
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();
m=checkTime(m);
s=checkTime(s);
document.getElementById('txt').innerHTML=h+":"+m+
":"+s;
t=setTimeout(function(){startTime()},500);
82
www.ebook3000.com
Dheeraj Singh
function checkTime(i)
if (i<10)
i="0" + i;
return i;
</script>
</HEAD>
<body onload="startTime()">
</body>
</HTML>
83
HTML & JavaScript Practice Questions
Coding Output
84
www.ebook3000.com
Dheeraj Singh
<HEAD>
<TITLE>Date</TITLE>
<script>
function strmethod()
var str =
document.getElementById("m").value;
document.getElementById("result").innerHTML
= "toUpperCase() : "+txt+"<br>replace() : "+rpc;
</script>
</HEAD>
<BODY>
<p>
85
HTML & JavaScript Practice Questions
Enter String :
<br><br>
<br>
<h2 id="result"></h2>
</p>
</BODY>
</HTML><HTML>
<HEAD>
<TITLE>Date</TITLE>
<script>
function strmethod()
var str =
document.getElementById("m").value;
www.ebook3000.com
Dheeraj Singh
document.getElementById("result").innerHTML
= "toUpperCase() : "+txt+"<br>replace() : "+rpc;
</script>
</HEAD>
<BODY>
<p>
Enter String :
<br><br>
<br>
<h2 id="result"></h2>
</p>
</BODY>
</HTML>
87
HTML & JavaScript Practice Questions
Coding Output
88
www.ebook3000.com
Dheeraj Singh
<HEAD>
<TITLE>Even Odd</TITLE>
<script>
function check()
var n = document.getElementById("m").value;
if(Math.floor(n%2)==0)
document.getElementById("result").innerHTML =
"Number is Even!!!";
else
document.getElementById("result").innerHTML =
"Number is Odd!!!";
</script>
</HEAD>
<BODY>
89
HTML & JavaScript Practice Questions
<p>
<br><br>
<br>
<h2 id="result"></h2>
</p>
</BODY>
</HTML>
90
www.ebook3000.com
Dheeraj Singh
Coding Output
91
www.ebook3000.com