Comp Journal 2
Comp Journal 2
PRACTICAL NO : 7 (SOP1)
AIM: JAVASCRIPT TO CHANGE 7 DIFFERENT AND DISTINCT BACKGROUND COLORS USING
FUNCTION
Filename: Color.html
<html>
<head>
<title>7 color change</title>
<script language="javascript">
function color1()
{
document.bgColor="red"
window.setTimeout("color2()",1000)
}
function color2()
{
document.bgColor="green"
window.setTimeout("color3()",1000)
}
function color3()
{
document.bgColor="violet"
window.setTimeout("color4()",1000)
}
function color4()
{document.bgColor="pink"
window.setTimeout("color5()",1000)
}
function color5()
{
document.bgColor="yellow"
window.setTimeout("color6()",1000)
}
function color6()
{
document.bgColor="orange"
window.setTimeout("color7()",1000)
}
function color7()
{
document.bgColor="grey"
window.setTimeout("color1()",1000)
}
function msg()
{
window.status="display of seven colors"
}
</script>
</head>
<body>
<form name="f1">
<input type="button" name="b1" value="colors" onMouseOver="color1()">
<input type="button" name="b2" value="message display" onClick="msg()">
</form>
</body>
</html>
Filename : color1.html
<html>
<head>
<title>7 color change</title>
<script language="javascript">
function color1()
{
document.bgColor="red"
window.setTimeout("color2()",5000)
}
function color2()
{
document.bgColor="green"
window.setTimeout("color3()",5000)
}
function color3()
{
document.bgColor="violet"
window.setTimeout("color4()",1000)
}
function color4()
{document.bgColor="pink"
window.setTimeout("color5()",1000)
}
function color5()
{
document.bgColor="yellow"
window.setTimeout("color6()",1000)
}
function color6()
{
document.bgColor="orange"
window.setTimeout("color7()",1000)
}
function color7()
{
document.bgColor="grey"
window.setTimeout("color1()",1000)
}
function msg()
{
alert("display of 7 colors")
}
</script>
</head>
<body onLoad="color1()" onUnLoad="msg()">
</body>
</html>
PRACTICAL NO : 8 (SOP3)
AIM: JAVASCRIPT PROGRAM TO COUNT NUMBER OF VOWELS USING STRING FUNCTION
AND CONTROL STRUCTURE.
CODING:
Filename: vowel.html
<html>
<head>
<title>
</title>
<script language="javascript">
function count()
{
var s,i,ch,c=0
s=f1.t1.value
for(i=0;i<=s.length;i++)
{
ch=s.charAt(i);
if(ch=="A"||ch=="a"||ch=="E"||ch=="e"||ch=="I"||ch=="i"||ch=="O"||ch=="o"||ch=="U"
||ch=="u")
c++;
}
alert("number of vowels "+c)
}
</script>
</head>
<body>
<form name="f1">
enter your name:
<input type="text" name="t1">
<input type="button" name="b1" value="count vowels" onClick="count()">
</form>
</body>
</html>
Practical no:9 (sop 4)
Aim: Javascript code to accept string from the user and reverse the string and check
wheather it is palindrome or not
filename:palindrome.html
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<script language="javascript">
function reverse()
{
var str=f1.t1.value ;
var final_str = str;
var split = str.split("");
var reverse = split.reverse();
var reverse_data = reverse.join("");
document.write("Reverse : "+reverse_data);
if (final_str==reverse_data)
document.write("<br>It is palindrome ");
else
document.write("<br>not palindrome ");
}
</script>
</head>
<body>
<form name="f1">
<input type="text" name="t1" placeholder="Enter a String">
<input type="submit" name="" onclick="reverse()">
</form>
</body>
</html>
PRACTICAL NO : 10 (SOP5)
AIM: Create event driven javascript program to convert temperature to and from
celcius,Fahrenheit
Filename : Celcius.html
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript">
function get_Fahrenheit()
{
var c,f;
c= parseInt(f1.t1.value);
//formula: (f-32)/9 = c/5;
f = c/5*(9)+32;
alert("Fahrenheit : "+f);
}
function get_Celsius()
{
var c,f
f= parseInt(f1.t2.value);
//formula: (f-32)/9 = c/5;
c = ((f-32)/9)*5;
alert("Celsius : "+c);
}
</script>
</head>
<body>
<form name="f1">
<input type="number" name="t1" placeholder="Temperature in Celsius">
<input type="button" name="b1"
value="submit"onClick="get_Fahrenheit()">
<br>
filename:grades.html
<!doctype html>
<html>
<head>
<title>
</title>
<script language="javascript">
function grade()
{
var m1,m2,m3,m4,m5,m6,avg;
m1=parseInt(f1.t1.value);
m2=parseInt(f1.t2.value);
m3=parseInt(f1.t3.value);
m4=parseInt(f1.t4.value);
m5=parseInt(f1.t5.value);
m6=parseInt(f1.t6.value);
avg=(m1+m2+m3+m4+m5+m6)/6;
alert("average marks of students is "+avg);
if(avg>=91)
alert("Grade A");
else
{
if(avg>=81)
alert("Grade b");
else
{
if(avg>=71)
alert("Grade C");
else
{
if(avg>=61)
alert("Grade D");
else
alert("Grade F");
}
}
}
}
</script>
</head>
<body>
<form name="f1">
Enter marks of English:
<input type="number" name="t1"><br><br>
Enter marks of Maths:
<input type="number" name="t2"><br><br>
Enter marks of physics:
<input type="number" name="t3"><br><br>
Enter marks of chemistry:
<input type="number" name="t4"><br><br>
Enter marks of IT:
<input type="number" name="t5"><br><br>
Enter marks of Biology:
<input type="number" name="t6"><br><br>
<input type="button" name="b1" value="click" onClick="grade()">
</form>
</body>
</html>
OUTPUT:
PRACTICAL NO : 7(SOP1)
PRACTICAL NO :8(SOP3)
Practical no 9(sop4)
Practical no 10(sop5)
practical no 11(sop 6)