Advance Java Script Coding Questions With Answer
Advance Java Script Coding Questions With Answer
<!DOCTYPE html>
<head>
<title>Q8 B sesction </title>
<script>
function addn()
{
var a,b;
a=parseInt(f1.t1.value);
b=parseInt(f1.t2.value);
document.write(a+b);
}
function mult()
{
var a,b;
a=parseInt(f1.t1.value);
b=parseInt(f1.t2.value);
document.write(a*b);
}
function div()
{
var a,b;
a=parseInt(f1.t1.value);
b=parseInt(f1.t2.value);
document.write(a/b);
}
function rem()
{
var a,b;
a=parseInt(f1.t1.value);
b=parseInt(f1.t2.value);
document.write(a%b);
}
</script>
</head>
<body>
<form name="f1">
enter 1st number <input type="text" name="t1">
enter 2nd number <input type="text" name="t2">
<input type="button" value="+" onclick="addn()">
<input type="button" value="*" onclick="mult()">
<input type="button" value="/" onclick="div()">
<input type="button" value="%" onclick="rem()">
</form>
</body>
</html>
<!DOCTYPE html>
<head>
<title>second method</title>
<script>
var a=parseInt(prompt("enter 1st number"));
var b=parseInt(prompt("enter 2st number"));
document.write("addition:"+ a+b);
document.write("multiplication:"+ a*b);
document.write("diviion:"+ a/b);
document.write("rem is :"+ a%b);
</script>
</head>
<body>
</body>
</html>
2. Display number sequence from 100 to 150 in following format. (100 101 102.............150)
Ans:( Event driven)
<!Doctype html>
<head>
<script>
function f1()
{
var a=100;
while(a<=150)
{document.writeln(a);
a++;
}
}
</script>
</head>
<body>
<form>
<input type="button" value="print numbers" onclick="f1()">
</form>
</body>
</html>
<!Doctype html>
<head>
<script>
var a=100;
while(a<=150)
{document.writeln(a);
a++;
}
</script>
</head>
<body>
</body>
</html>
<!Doctype html>
<head>
<script>
function f1()
{fact=1;
var a=parseInt(prompt("enter number"));
while(a>=1)
{
fact=fact*a;
a=a-1;
}
document.write(fact);
}
</script>
</head>
<body>
<form>
<input type="button" value="print numbers" onclick="f1()">
</form>
</body>
</html>
<!Doctype html>
<head>
<script>
fact=1;
var a=parseInt(prompt("enter number"));
while(a>=1)
{
fact=fact*a;
a=a-1;
}
document.write(fact);
</script>
</head>
<body>
</body>
</html>
4. Accept any string from user and count and display number of vowels occurs in it
<!Doctype html>
<head>
<title></title>
<script>
function f1()
{var i,ch,c,a;
c=0;
a=prompt("enter string to count wowel");
for(i=0;i<=a.length;i++)
{
ch=a.charAt(i);
if(ch=="A" || ch=="a" || ch=="E" || ch=="e" || ch=="i" || ch=="I" || ch=="o" || ch=="O" ||
ch=="U" ||ch=="u" )
{c=c+1;}
}
document.write(c);
}
</script>
</head>
<form>
<input type="button" value="iske uuper mouse leke jao" onclick="f1()">
</form>
<body>
</body>
</html>
<!Doctype html>
<head>
<title></title>
<script>
var i,ch,c,a;
c=0;
a=prompt("enter string to count wowel");
for(i=0;i<=a.length;i++)
{
ch=a.charAt(i);
if(ch=="A" || ch=="a" || ch=="E" || ch=="e" || ch=="i" || ch=="I" || ch=="o" || ch=="O" ||
ch=="U" ||ch=="u" )
{c=c+1;}
}
document.write(c);
</script>
</head>
<body>
</body>
</html>