Professional Documents
Culture Documents
Muskan Dhingra 19BCE1148 Internet and Web Programming Java Script Lab Homework
Muskan Dhingra 19BCE1148 Internet and Web Programming Java Script Lab Homework
19BCE1148
INTERNET AND WEB PROGRAMMING
JAVA SCRIPT
LAB HOMEWORK
QUESTION 1
CODE:
<html>
<head>
<style>
table,th,td{
</style>
<script>
document.write( "</table>" )
</script>
</head>
</html>
OUTPUT:
QUESTION 2:
PART A)
CODE:
<html>
<head>
<title>QUESTION 2</title>
</head>
<script>
function vowel()
flag=0;
switch(n[i])
case 'a':
case 'e':
case 'i':
case 'o':
case 'u': alert("The position in the string of the left-most vowel is: " +(i+1));
flag = 1;
break;
default : break;
if(!flag)
</script>
<body onload="vowel()">
</body>
OUTPUT:
PART B:
CODE:
<html>
<head>
<title>QUES2-B</title>
</head>
<script type="text/javascript">
function rev()
for(i=n.length-1;i>=0;i--)
alert(str);
</script>
<body onload="rev()">
</body>
OUTPUT:
QUESTION 3:
CODE:
<html>
<head>
<script type="text/javascript">
document.write( "<table border = 1 cellpadding = 5px> " )
for (var x=0; x<=15; x++) {
if (x === 0) {
document.write("<tr><td>" + x + " is even" + "</td></tr>");
}
else if (x % 2 === 0) {
document.write("<tr><td>" + x + " is even" + "</td></tr>");
}
else {
document.write("<tr><td>" + x + " is odd" + "</td></tr>");
}
}
</script>
</head>
<body>
</body>
</html>
OUTPUT:
QUESTION4:
CODE:
<html>
<head>
<title></title>
<script type="text/javascript">
function calc()
form=document.getElementById("form1");
sub1=form.sub1.value;
sub2=form.sub2.value;
sub3=form.sub3.value;
sub4=form.sub4.value;
total=parseInt(sub1)+parseInt(sub2)+parseInt(sub3)+parseInt(sub4);
form.total.value= total;
form.avg.value= parseInt(total)/4;
if(sub1<35||sub2<35||sub3<35||sub4<35)
{ form.result.value="Fail";}
else {form.result.value="Pass";}
// Grading system.
if(form.avg.value>90)
{form.grade.value="A";}
{form.grade.value="B";}
{form.grade.value="D";}
{form.grade.value="E";}
</script>
</head>
<body>
<form id="form1">
</body>
</html>
OUTPUT:
QUESTION 5:
<html>
<head>
<meta charset="utf-8">
<script>
var sum = 0;
if (x % 3 === 0 || x % 5 === 0)
{
sum += x;
alert(sum);
</script>
</head>
<body>
</body>
</html>
OUTPUT:
QUESTION 6:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>QUESTION-6</title>
</head>
<body>
<script>
var dist=999;
var tmp;
for(var i=0;i<n;i++) {
for(var j=i+1;j<n;j++) {
if(arr[i]>arr[j])
tmp=arr[i]-arr[j];
else
tmp=arr[j]-arr[i];
if(tmp<dist) {
dist=tmp;
pos_i=i; pos_j=j;
ele_i=arr[i]; ele_j=arr[j];
pos_i++;
pos_j++;
</script>
</body>
</html>
OUTPUT:
QUESTION 7:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>QUESTION-7</title>
</head>
<body>
<script>
if(str.slice(-1)=='y')
else
if(str.slice(-1)=='s'||str.slice(-1)=='h')
else
document.write("The plural "+str.slice(0,-1)+"s");
</script>
</body>
</html>
OUTPUT: