Program For Javascript
Program For Javascript
Program For Javascript
var sub=a-b;
document.write( "The Subtraction is" +sub );
document.write("</br>");
</script></head></html>
2) Determine if a student has passed in his exam or not. if the marks are
greater than 40 then he has a passed else he has a failed.
<html>
<head>
<script type=”text/javscript”>
Var a;
if(a>40)
else
</script></head></html>
3) Determine what grade he has obtained based on the marks obtained if 90-100 is a+; 80-90
is a ; 70-80 is b+; 60-70 is b ; 50-60 is c; 40-50 is d and below 40 is fail [hint : use the if-else
if..-else
<html>
<head>
<script type="text/javascript">
else
document.write("You Failed");
</script></head></html>
4) Write a aprogram to check the given alphabet is vowel or not using switch statement
<html>
<head>
<script type="text/javascript">
switch(alpha)
case 'a':
document.write("Its a Vowel");
break;
case 'e':
document.write("Its a Vowel");
break;
case 'i':
break;
case 'o':
document.write("Its a Vowel");
break;
case 'u':
document.write("Its a Vowel");
break;
case 'A':
document.write("Its a Vowel");
break;
case 'E':
document.write("Its a Vowel");
break;
case 'O':
document.write("Its a Vowel");
break;
case 'I':
document.write("Its a Vowel");
break;
case 'U':
document.write("Its a Vowel");
break;
default:
document.write("Consonant");
</script>
</head>
</html>
<html>
<head>
<script type="text/javascript">
var a;
var fact=1;
for(a=5;a>=1;a--)
fact= fact*a;
</script>
</head>
</html>
6) Writea JavaScript program to get the first n Fibonacci numbers.
note : the Fibonacci sequence is the series of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, . . each
subsequent number is the sum of the previous two numbers.
<html>
<head>
<script type="text/javascript">
var a=0;
var b=1;
var c;
var i;
var number ;
for(i=1;i<number;++i)
c=a+b;
document.write(+c +",");
a=b;
b=c;
</script>
</head>
</html>
Write a JavaScript program to design the following pattern, using a nested for
loop.
*
**
7
** *
** * *
** * * *
<html>
<head>
<body>
<p>Printing a triangle</p>
<script type="text/javascript">
var i, j;
document.write(i);
document.write('<br/>');
</script>
</body>
</html>
8) Write a program to check the greatest number among 3 number
<html>
<head>
<script type="text/javascript">
else
else
</script>
</head>
</html>
Q9 Write a program to find the sum of given number for e. g (given number =5 i.e. 1+2+3+4+5 =15)
<html>
<head>
<script type="text/javascript">
var a;
var sum=0;
for(a=1;a<=5;a++)
sum= sum+a;
</script>
</head></html>
<html>
<head>
<script type="text/javascript">
if(a%2==0)
else
</script>
</head></html>
Q10) write a program to print table of given number
<html>
<head>
<script type="text/javascript">
var a;
var table;
for(a=1;a<=10;a++)
table=p*a;
</script>
</head>
</html>
Q11)
Write a JavaScript program to design the following pattern, using a nested for loop.
1
12
123
1234
12345
<html>
<head>
<body>
<script type="text/javascript">
var i, j;
document.write(j);
document.write('<br/>');
</script>
</body>
</html>