Cap214: Fundamentals of Web Programming
Cap214: Fundamentals of Web Programming
HOMEWORK: 3
Submitted by:
Section: D3901
Group: 1
Submitted to:
Ans.:
<html>
<head>
<title>Expression</title>
</head>
<body>
<script language="JavaScript">
document.write("1"+2+4);
document.write("<br>");
document.write(2+5+"8");
</script>
</body>
</html>
“1”+2+4: 124
2+5+”8”: 78
i) First Name
ii) Last Name
iii) Date of Birth
iv) Gender
v) Email ID
vi) Address
vii) ZIP Code
Ans.:
<html>
<head>
<center><strong><u>Registration Page</strong></U></center>
<script type="text/javascript">
function success()
</script>
</head>
<body bgcolor="AQUA">
<form>
Your Name:
<br><br>
First Name:
Last Name:
<BR><BR>
DOB:
<select>
<option value="1">1
<option value="2">2
<option value="3">3
<option value="4">4
<option value="5">5
<option value="6">6
<option value="7">7
<option value="8">8
<option value="9">9
<option value="10">10
<option value="11">11
<option value="12">12
<option value="13">13
<option value="14">14
<option value="15">15
<option value="16">16
<option value="17">17
<option value="18">18
<option value="19">19
<option value="20">20
<option value="21">21
<option value="22">22
<option value="23">23
<option value="24">24
<option value="25">25
<option value="26">26
<option value="27">27
<option value="28">28
<option value="29">29
<option value="30">30
<option value="31">31
</option>
</select>
<select>
<option value="January">Jan
<option value="Febrary">Feb
<option value="March">Mar
<option value="April">Apr
<option value="May">May
<option value="June">June
<option value="July">July
<option value="August">Aug
<option value="September">Sep
<option value="October">Oct
<option value="November">Nov
<option value="December">Dec
</option>
</select>
<select>
<option value="2000">00
<option value="1999">99
<option value="1998">98
<option value="1997">97
<option value="1996">96
<option value="1995">95
<option value="1994">94
<option value="1993">93
<option value="1992">92
<option value="1991">91
<option value="1990">90
</option>
</select>
<BR><br>
GENDER:
<select>
</option>
</select>
<br><br>
Address:
<br><br>
Zip Code:
<input type="text">
<br><br><br><br>
</form>
</body>
</html>
Ans.:
<html>
<head><title>String</title></head>
<body>
<script type="text/javascript">
var ch;
document.write("<br>");
if(ch==1)
{
document.write("<br>");
document.write("<br>");
document.write(b.toLowerCase());
else if(ch==2)
document.write("<br>");
document.write("<br>");
document.write(b.charAt(10));
</script>
</body>
</html>
PART: “B”
Ans.:
<html>
<head><title>Prime number</title></head>
<body>
<script type="text/javascript">
var i;
var count=0;
var num;
for(i=2;i<=num;i++)
if(num%i==0)
count++;
if(count==1)
document.write("Number is prime");
else
}
</script>
</body>
</html>
Ans.:
Control structures
if( myVariable == 2 ) {
myVariable = 1;
} else {
myVariable = 0;
'If' statements can also test for the occurence of a child object of
an object that may not exist. For example, some browsers
provide document.body.style while some older browsers do not
even provide document.body. In these browsers, writing
'if( document.body.style )' would just produce an error (see the
section on 'Variables' subsection 'Avoiding errors with
variables'). In order to solve this problem, we could write this:
As always, there is an exception. Nested 'if' statements like this
can start to get diffi cult to manage:
if( myVariable == 2 ) {
myVariable = 1;
} else {
if( myVariable == 5 ) {
myVariable = 3;
} else {
myVariable = 4;
starting_initialise
This is where we defi ne new variables that you will use in the
loop, typically for use with incremental counting. As with all
variables, you must declare them (if you have not done so
already). You can defi ne multiple variables if needed, using:
myVariable1++, myVariable2 -= 4
myArray[myVariable] = 1;
The 'for - in' loop is used to cycle through all exposed properties
of an object (or array). Every time you create properties or
methods on an object, these will be added to the list of
properties that will be exposed. Most internal properties (the
ones that JavaScript creates) will also be exposed, but JavaScript
engines are allowed to hide internal properties and methods if
they want to. You should not rely on any specifi c behaviour here,
but note that some browsers will give the internal properties and
methods of intrinsic objects, and some will not.
Again, you should declare the variable names that you use, if you
have not done so already. The syntax of the 'for - in' loop is as
follows:
Note that if you use this loop on an array, it will list the
numbered and named keys, including the internal 'length'
property. It is very easy to make mistakes here, so be careful not
to mistake these property types for each other.
var myVariable = 1;
myArray[myVariable] = 1;
myVariable++;
This is similar to the while loop, but with an important diff erence.
The condition is evaluated at the end of the loop, meaning that
even if the condition is never satisfi ed, it will still run through the
loop at least once.
var myVariable = 1;
do {
myArray[myVariable] = 1;
myVariable++;
switch(myVar) {
case 1:
case 'sample':
case false:
//this is executed
default:
//this is executed
If a case is satisfi ed, the code beyond that case will also be
executed unless the break statement is used. In the above
example, if myVar is 1, the code for case 'sample', case false and
default will all be executed as well.
if( document.getElementById ) {
var myVariable = 1;
} else {
var myVariable = 0;
}
PROGRAM TO PRINT THE FIRST TEN NUMBERS
<html>
<head>
<script language="Javascript">
var a=0;
var i;
var n;
for(i=1;i<=n;i++)
if(n%i==0)
a++;
if(a==2)
else
</head>
</html>
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Ans.:
<html>
<head><title>Pattern</title></head>
<body>
<script type="text/javascript">
var i;
var j;
for(i=1;i<=5;i++)
for(j=1;j<=i;j++)
document.write(+j);
}
document.write("<br>");
</script>
</body>
</html>