Ganesh CSS 1 To 8
Ganesh CSS 1 To 8
Condintional statement
1] If-else
<script>
var a=parseInt(prompt("enter the number that are check to even and odd")); if(a
%2==0)
document.write(a+" is even");
else
document.write(a+" is odd");
</script>
Output:
2] If-else Ladder
<script>
</script>
Output :
3] Switch case
<script>
var day;
day=parseInt(prompt("enter the day between 1-7"));
switch(day){
case 1:
document.write("monday");
break;
case 2:
document.write("tuesday");
break;
case 3:
document.write("wednesday");
break;
case 4:
document.write("thursday");
break;
case 5:
document.write("friday");
break;
case 6:
document.write("saturday");
break;
case 7:
document.write("sunday");
break;
default:
</script>
Output:
Looping statements
1]for loop
<script>
for(var i=1;i<=10;i++){
document.write("<br>"+i);
}
</script>
Output:
2] While-loop
<script>
var a;
a=1;
document.write("using while loop");
while(a<=30){
document.write("<br>"+a); a+
+;
};
</script>
Output:
3] Do-while
<script>
var a;
a=1;
document.write("using do while loop");
do{
document.write("<br>"+a); a+
+;
}while(a<=20);
</script>
Output:
Extra programs
1]factorial
<script>
var num=parseInt(prompt("enter a number"));
var fact=1;
for(var i=1;i<=num;i++){
fact=fact*i;
}
document.write("factorial of given number is "+fact);
</script>
Output:
2] Fibonacci series
<script>
var num1=1,num2=2,num3;
var limit=parseInt(prompt("enter the limit"));
document.write("<br> fibonacci series:");
document.write("<br>"+num1+"<br>"+num2);
for(var i=1;i<limit;i++)
{num3=num1+num2;
document.write("<br>"+num3);
num1=num2;
num2=num3;
}
</script>
Output:
3] calculator
<script>
var a,b,c;
a=parseInt (prompt("enter the first number"));
b=parseInt (prompt("enter the second number"));
c=prompt("enter the operation do you perfom like +,-.*,/");
switch(c){
case "+":
document.write("addition is:"+(a+b));
break;
case "-":
document.write("Sub is:"+(a-b));
break;
case "*":
document.write("Mul is:"+(a*b));
break;
case "/":
document.write("Div is:"+(a/b));
break;
default:
</script>
Output:
Name :Ganesh Chandrakant Zore Roll no:92
Practical 3rd
<body>
<script>
var i;
emp[0]="mayur";
emp[1]="onkar";
emp[2]="ganesh";
for(i=0;i<emp.length;i++){
document.write("<br>"+emp[i]);
</script>
</body>
</html>
Output:
Eg 2]
<html>
<body>
<script>
var i;
var emp=["onkar","mayur","ganesh","balaji"];
for(i=0;i<emp.length;i++){
document.write("<br>"+emp[i]);
}
</script>
</body>
</html>
Output :
Extra Programs:
1] Perform Array function
<script>
var array=new Array();
array[0]=12;
array[1]=67;
array[2]=22;
array[3]=44;
array[4]=30;
var s=array.sort();
document.write("sorted array :"+s);
var s=array.sort();
var c=s.reverse();
document.write("<br>revers array :"+c);
var i=array.indexOf(22);
document.write("<br>index of 67:"+i);
var l=s.lastIndexOf(22)
document.write("<br>last index of 22:"+l);
//var m=array.find(44);
//document.write("<br>after find :"+m);
array.push(33,54);
document.write("<br>after push :"+array);
array.unshift(65,66);
document.write("<br>after unshift :"+array);
array.pop();
document.write("<br>after pop :"+array);
array.shift();
document.write("<br>after shift :"+array);
</script>
Output:
</script>
Output:
2]shift and unshift methods.
<script>
var a=new Array(1,2,3,4,5);
document.write("array is:"+a);
a.shift();
document.write("<br>array after shift:"+a);
a.unshift();
document.write("<br>array after unshift:"+a);
</script>
Output:
Name :Ganesh Chandrakant Zore Roll no:92
Functions:
Eg 1]
<html>
<script>
function msg(){
alert("Hello");
</script>
<body>
</body>
</html>
Output:
Eg 2]
<html>
<script>
var a=parseInt(prompt("enter the number that you want to make the
cube")); function cube(p){
var c=p*p*p;
alert("cube is :"+c);
}
function sq(r){
var k=r*r;
alert("cube is :"+k);
}
</script>
<body>
<input type="button" onclick="cube(a)" value="find the cube" />
<input type="button" onclick="sq(a)" value="find the square" />
</body>
</html>
Output :
Eg.Return function:
<html>
<body>
<script>
function getinfo(){
</body>
</html>
Output:
Eg.function object
<html>
<body>
<script>
var add=new Function ("num1","num2","return num1+num2");
document.writeln("addition is:"+add(5,10));
</script>
</body>
</html>
Output:
Name :Ganesh Chandrakant Zore Roll no:92
<!DOCTYPE html>
<html>
<head>
<title>Admission Form</title>
</head>
<body>
<h2>Admission Form</h2>
<form>
<label for="fullName">Full Name:</label>
<input type="text" id="fullName" name="fullName"><br><br>
<label for="address">Address:</label><br>
<textarea id="address" name="address" rows="4" cols="50"></textarea><br><br>
</select><br><br>
<option value="">SY</option>
<option value="">TY</option>
</select><br><br>
<label>Subject:</label><br>
<input type="checkbox" id="java" name="subject" value="JAVA">
<label for="java">JAVA</label>
<input type="checkbox" id="html" name="subject" value="HTML">
<label for="html">HTML</label>
<input type="checkbox" id="javascript" name="subject" value="JavaScript">
<label for="javascript">JavaScript</label>
<input type="checkbox" id="php" name="subject" value="PHP">
<label for="php">PHP</label>
<input type="checkbox" id="cpp" name="subject" value="C++">
<label for="cpp">C++</label><br><br>
<label>Gender:</label><br>
<input type="radio" id="male" name="gender" value="Male">
<label for="male">Male</label>
<input type="radio" id="female" name="gender" value="Female">
<label for="female">Female</label>
<input type="radio" id="other" name="gender" value="Other">
<label for="other">Other</label><br><br>
<label>Caste:</label><br>
<input type="radio" id="open" name="caste" value="Open">
<label for="open">Open</label>
<input type="radio" id="obc" name="caste" value="OBC">
<label for="obc">OBC</label>
<input type="radio" id="nt" name="caste" value="NT">
<label for="nt">NT</label><br><br>
<label for="certification">Certification:</label>
<input type="text" id="certification" name="certification"><br><br>
<button type="submit">Submit</button>
</form>
</body>
</html>