0% found this document useful (0 votes)
24 views

Javascript Complete

The document contains 13 programming questions and answers in JavaScript. Each question asks the programmer to write code to solve a specific problem such as adding numbers, calculating average, checking if a number is positive/negative/zero, finding the largest of two or three numbers, or determining if a year is a leap year. The answers provide the code to solve each problem using JavaScript syntax like variables, prompts, conditionals, and loops.

Uploaded by

niloorampoyam08
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Javascript Complete

The document contains 13 programming questions and answers in JavaScript. Each question asks the programmer to write code to solve a specific problem such as adding numbers, calculating average, checking if a number is positive/negative/zero, finding the largest of two or three numbers, or determining if a year is a leap year. The answers provide the code to solve each problem using JavaScript syntax like variables, prompts, conditionals, and loops.

Uploaded by

niloorampoyam08
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

1

PROGRAMING OF JAVASCRIPT var a = parseInt(a);


var b = parseInt(b);
var c = parseInt(c);
Q1.Draw a Programmed Add three no.
var d = parseInt(a);
?
var e = parseInt(b);
Ans.
sum=a+b+c+d+e;
<html>
av=sum/5
<head>
document.write(alert(av));
<body>
</script>
<script type = "text/javascript">
</head>
var a = prompt("pls enter no for a");
</body>
var b = prompt("pls enter no for b");
</html>
var c = prompt("pls enter no for c");
var a = parseInt(a)
Q3. Simple Interest
var b = parseInt(b)
Ans.
var c = parseInt(c)
<html>
var sum = a+b+c;
<head>
document.write(alert(sum));
<body>
</script>
<Script type ="text/JavaScript">
</head>
var p = prompt("p=");
</body>
var r = prompt("r=");
</html>
var t = prompt("t=");
var p = parseInt(p)
Q2. Draw a Programme that accept
var r = parseInt(r)
five(5) no and print its average ?
var t = parseInt(t)
<html>
var si = p*r*t/100;
<head>
document.write(si);
<body>
</Script>
<script type = "text/javascript">
</body>
var a = prompt("pls enter no for a","l=");
</head>
var b = prompt("pls enter no for
</html>
b","w=");
var c = prompt("pls enter no for
c","w=");
Q4. Draw a Programme that print
var d = prompt("pls enter no for
Square of any no. ?
d","w=");
Ans. <html>
var e = prompt("pls enter no for
<head>
e","w=");
2

<body> <body>
<script type = "text/javascript"> <Script type ="text/JavaScript">
var l = prompt("pls enter no for a","l="); var a = prompt("a=");
var w = prompt("pls enter no for var b = prompt("b=");
a","w="); if(a<b)
a=l*w; {
document.write(alert(a)); document.write("A is smallest");
</script> }
</head> </Script>
</body> </body>
</html> </head>
</html>
Q5. ConfirmBox
Ans. Q7. Conditional (Ternary) Operator
<html> Ans.
<head> <html>
<body> <head>
<Script type ="text/JavaScript"> <body>
var a = confirm ("Are You Happy"); <Script type ="text/JavaScript">
if (a ==1) var a = prompt("a=");
{ var b = prompt("b=");
document.write("As You are happy"); (a<b) ? document.write("A is
} smallest"):document.write("B is
else smallest");
{ </Script>
document.write("not happy "); </body>
} </head>
</Script> </html>
</body>
</head> Q8. week of day (using else if)
</html> Ans.
<html>
If and if else <head>
<body>
Q6. if structure
<Script type ="text/JavaScript">
Ans.
var no = prompt("no=");
<html>
if (no == 1)
<head>
3

{ Q9. Draw a Programe that find largest


document.write("Monday"); of two no. ?(using if else)
} Ans.
else if (no==2) <html>
{ <head>
document.write("Tuesday"); <body>
} <script type = "text/javascript">
else if (no==3) var a = prompt("pls enter no for a","a=");
{ var b = prompt("pls enter no for
document.write("wdensday"); b","b=");
} if(a>=b)
else if (no==4) {
{ document.write("<b> a is largest</b>")
document.write("Thirsday"); }
} else
else if (no==5) {
{ document.write("<b> b is largest</b>")
document.write("Firday"); }
} </script>
else if (no==6) </head>
{ </body>
document.write("Saturday"); </html>
}
else if (no==7) Q10. Draw a Program that find largest
{ of three no. ?
document.write("Sunday"); Ans.
} <html>
else <head>
{ <body>
document.write("Invilid no"); <script type ="text/javascript">
} var a= prompt("a");
</Script> var b= prompt("b");
</body> var c= prompt("c");
</head> if(a>b&&a>c)
</html> {
document.write("<b>a is largest</b>")
}
4

else if (b>c) </html>


{
document.write("<b>b is largest</b>") Q12. Draw a Programme That accept
} year and find leap or not leap year?
else Ans. <html>
{ <head>
document.write("<b> c is largest</b>"); <body>
} <script type = "text/javascript">
</script> var a = prompt("pls enter no for a","a=");
</head> if(a%4==0)
</body> {
</html> document.write("leap year");
Q11. Draw a Programe that accept no. }
and print negative (-1), positive (1) Or else
Zero(0) ? {
Ans. document.write("not leap year");
<html> }
<head> </script>
<body> </head>
<script type = "text/javascript"> </body>
var a = prompt("pls enter no for a","a="); </html>
if(a<0)
{ Q13. Draw a Programme That accept
document.write("<b> a is year and find leap or not leap year?
nagetive</b>"); Ans.
} <html>
if(a>0) <head>
{ <body>
document.write("positive"); <script type = "text/javascript">
} var a = prompt("pls enter no for a","a=");
else if(a%4==0)
{ {
document.write("zero"); document.write("leap year");
} }
</script> else
</head> {
</body> document.write("not leap year");
5

} document.write("Sunday");
</script> break;
</head> default:
</body> document.write("Invilid no");
</html> }
</Script>
Switch Case </body>
</head>
Q14. week of day (using Switch Case
</html>
structure)
Ans.
<html> For Loop
<head> Q15. Draw a Programme that print 1 to
<body> 10 no. ?
<Script type ="text/JavaScript"> Ans.
var no = prompt("no="); <html>
var no = parseInt(no) <head>
switch (no) <body>
{ <script type = "text/javascript">
case 1: for(i=1;i<=10;i++)
document.write("Monday"); {
break; document.write(i);
case 2: }
document.write("Tuesday"); </script>
break; </head>
case 3: </body>
document.write("Wedensday"); </html>
break;
case 4: Q16. Draw a Programme that print 10
document.write("Thirsday"); to 1 no. ?
break; Ans.<html>
case 5: <head>
document.write("Friday"); <body>
break; <script type = "text/javascript">
case 6: //var a = prompt("pls enter no for
document.write("Saturday"); a","a=");
break; for(i=10;i>=1;i--)
case 7: {
6

document.write("<br>",i); sum = sum + i;


} document.write("<br>",sum);
</script> }
</head> </Script>
</body> </body>
</html> </head>
</html>
Q17.Draw a Programme that print 1 to
100 even no. ? Q19. Multi table of any no with table
Ans. Ans.
<html> <html>
<head> <head>
<body> <body>
<script type = "text/javascript"> <table border>
//var a = prompt("pls enter no for <tr><td>enter your choise
a","a="); No.</td></tr>
for(i=1;i<=100;i++) <script type = "text/javascript">
{ var num = prompt("pls enter no");
if(i%2==1) for(var i =1;i<=10; i++)
{ {
document.write("<br>",i); document.write("<tr><td>"+num*i+"</t
} d></tr>");
} }
</script> </script>
</head> </head>
</body> </body>
</html> </html>

Q18. Sum of 1 to 10 no? (for loop) Q20. Draw a Program that accept Base
Ans. and Power and print its value?
<html> Ans.
<head> <html>
<body> <head>
<Script type ="text/JavaScript"> <body>
sum = 0; <script type = "text/javascript">
for (i =1; i<= 10; i++) var b = prompt("pls enter no for b");
{ var p = prompt("pls enter no for p");
7

var fact=1; <body>


var i=1; <Script type ="text/JavaScript">
for(i=1;i<=p;i++) var no = prompt("no=");
{ for (i =1; i<= no; i++)
fact=fact*b; {
} document.write("<br>1/",i);
document.write(alert(fact)); }
</script> </Script>
</head> </body>
</body> </head>
</html> </html>

Q21. Draw a Program that print Q23. Fibonacci series


Factorial of any no.? Ans.
Ans. <html>
<html> <head>
<head> <body>
<body> <Script type ="text/JavaScript">
<script type = "text/javascript"> var no = prompt("Enter no");
var num = prompt("pls enter no for a"); a=0;
var fact=1; b=1;
var i=1; document.write(a,"<br>");
for(i=1;i<=num;i++) document.write(b);
{ for (i=1;i<=no;i++)
fact=fact*i; {
} var c = a+b;
document.write(alert(fact)); document.write("<br>",c)
</script> a=b;
</head> b=c;
</body> }
</html> </Script>
</body>
Q22. Draw a Programme That accept </head>
no and Print 1/1, 1/2, 1/3.......no? </html>
Ans
<html> Nested for loop
<head>
8

Q24. Multi table no of 1 to 10 <script


no? type="text/javascript">
Ans. var i=0;
<html> for(i=0; i<=10; i++)
<head> {
<body> if(i == 4) { break;}
<Script type ="text/JavaScript"> document.write("The
for (var i =1; i<= 10; i++) number is "+i+"<br/>");
{ }
for (var j=1;j<=10;j++) </script>
{ </body>
document.write("<br><tr><td>"+ </html>
i*j+"</td></tr>");
} Continue
} Q26. Continue
</Script> Ans.
</body> <html>
<head>
</head>
<body>
</html>
<script type = "text/javascript">
//var num = prompt("pls enter no");
Break var i=0;
Q25. Break for(i=0; i<=10; i++)
Ans. {
if(i == 3) {continue}
<html>
if(i == 4) {continue}
<head>
if(i == 5) {continue}
<title>example of continue document.write("The number is "+ i +
statement</title> "<br/>");
</head> }
<body> </script>
</head>
9

</body> </script></head>
</html> <body>
<script type ="text/javascript">
Function add (3);
Q27. Function add (5);
Ans. </script>
<html> </body>
<head> </html>
<script type = "text/javascript">
Q29. Draw a Programme that accept
function showcube (x)
character and print vowel or consonent
{
? (not run)
document.write("The cube of: "
Ans.
+x+ "is" +x*x*x+ "<br>")
<html>
} <head>
</script></head> <body>
<body> <script type = "text/javascript">
<script type ="text/javascript"> var let = prompt("your letter");
showcube (3); if(let == 'a' ||
showcube (5); let =='e'||
showcube (7); let=='i'||
</script> let='o'||
</body> let='u')
{
</html>
alert ("Your letter is Vowel");
}
Q28. Add two no with function?
else
Ans.
{
<html> alert ("Your letter is cons");
<head> }
<script type = "text/javascript"> //document.write("<br>",num*i);
function add (a) </script>
{ </head>
document.write("The cube of: " +a+ </body>
"is" +a+a+ "<br>") </html>
} <html>
10

<head>
Q Output your name
ans.
<script type = "text/javascript">
var name = prompt("pls enter character
your name","text type here");
</script>
</head>
<body>
<script type = "text/javascript">
document.write("<h2>Your name is
"+name+"</h2>");
</script>
</body>
</html>

You might also like