Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
117 views

Advance Java Script Coding Questions With Answer

The document contains 4 JavaScript coding questions with answers that are either event-driven or not event-driven. The questions include: 1) Performing math operations on two user-input numbers, 2) Displaying a number sequence from 100 to 150, 3) Calculating the factorial of a user-input number, and 4) Counting the vowels in a user-input string. For each question, an event-driven answer using buttons and prompts is provided, as well as a non-event-driven version using only prompts.

Uploaded by

shreyajadhav1724
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
117 views

Advance Java Script Coding Questions With Answer

The document contains 4 JavaScript coding questions with answers that are either event-driven or not event-driven. The questions include: 1) Performing math operations on two user-input numbers, 2) Displaying a number sequence from 100 to 150, 3) Calculating the factorial of a user-input number, and 4) Counting the vowels in a user-input string. For each question, an event-driven answer using buttons and prompts is provided, as well as a non-event-driven version using only prompts.

Uploaded by

shreyajadhav1724
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Advance java Script Coding questions with Answer

Write event driven JavaScript program for the following


1. Display Addition, multiplication, division and remainder of two numbers, which were
accepted from user
Ans: (Event driven)

<!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>

Ans(Not event driven)

<!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>

Ans: (not Event driven)

<!Doctype html>
<head>
<script>
var a=100;
while(a<=150)
{document.writeln(a);
a++;
}
</script>
</head>
<body>
</body>
</html>

3. Find and display factorial of given number


Ans: (Event driven)

<!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>

Ans: (Not Event driven)

<!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>

Ans: (Not Event driven)

<!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>

You might also like