Cap214: Fundamentals of Webprogramming: Submitted by
Cap214: Fundamentals of Webprogramming: Submitted by
HOMEWORK: 4
Submitted by:
Section: D3901
Group: 1
Submitted to:
Ans.:
<head>
<script language="Javascript">
var i;
for(i=0;i<10;i++)
arr[i]=prompt(" ");
document.write("<br>");
document.write("Entered elements are as follows: ");
document.write("<br>");
for(i=0;i<10;i++)
document.write(" ",arr[i]);
arr.reverse();
document.write("<br>");
document.write("<br>");
for(i=0;i<10;i++)
document.write(" ",arr[i]);
</script>
</body>
</html>
2. Write a program in JavaScript that accepts a
number as an input from the user and prints the
message “Number is greater than 100” if the number
is greater than 100 or prints “Number is smaller than
100” if the number is smaller than 100.
Ans.:
<head>
<script language="Javascript">
var x;
document.write("<br>");
if(x>100)
else
{
document.write("Number is smaller than 100");
</script>
</body>
<html>
Ans.:
<head>
<script language="Javascript">
var i,j;
for(i=0;i<3;i++)
arr1[i]=new Array();
for(j=0;j<3;j++)
arr1[i][j]=parseInt(prompt(" "));
for(i=0;i<3;i++)
arr2[i]=new Array();
for(j=0;j<3;j++)
arr2[i][j]=parseInt(prompt(" "));
}
document.write("<br>");
document.write("<br>");
for(i=0;i<3;i++)
for(j=0;j<3;j++)
document.write(" ",arr1[i][j]);
document.write("<br>");
document.write("<br>");
document.write("<br>");
for(i=0;i<3;i++)
for(j=0;j<3;j++)
document.write(" ",arr2[i][j]);
document.write("<br>");
}
document.write("<br>");
for(i=0;i<3;i++)
add[i]=new Array();
for(j=0;j<3;j++)
add[i][j]=arr1[i][j]+arr2[i][j];
document.write("<br>");
document.write("<br>");
for(i=0;i<3;i++)
for(j=0;j<3;j++)
document.write(" ",add[i][j]);
document.write("<br>");
</script>
<body bgcolor="Grey" text="White">
<p>
</p>
</body>
<html>
PART: “B”
4. With the help of an example, explain the use of
onMouseOver and onMouseOut event handlers in
JavaScript?
Ans.:
<html>
<body>
<!--
function backImage()
document.imgGGL.src="ggl.gif";
-->
</script>
</body>
</html>
Ans.:
With JavaScript, it is possible to execute some code after a specified time-
interval. This is called timing events.
It's very easy to time events in JavaScript. The two key methods that are
used are:
The setTimeout() method returns a value - In the statement above, the value
is stored in a variable called t. If you want to cancel this setTimeout(), you
can refer to it using the variable name.
The second parameter indicates how many milliseconds from now you want
to execute the first parameter.
<head>
<script type="text/javascript">
function timedMsg()
</script>
</head>
<body>
<form>
</form>
</body>
</html>
Syntax:
clearTimeout(setTimeout_variable)
<head>
<script type="text/javascript">
var c=0;
var t;
var timer_is_on=0;
function timedCount()
document.getElementById('txt').value=c;
c=c+1;
t=setTimeout("timedCount()",1000);
function doTimer()
if (!timer_is_on)
timer_is_on=1;
timedCount();
function stopCount()
clearTimeout(t);
timer_is_on=0;
</script>
</head>
<body>
<form>
</form>
</body>
</html>
Ans.:
JavaScript has three kinds of popup boxes (Dialog Boxes): Alert
box, Confirm box, and Prompt box.
<head>
<script type="text/javascript">
function show_alert()
function show_confirm()
if (r==true)
else
function show_prompt()
}
}
</script>
</head>
<body>
</body>
</html>