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

Web App Mid Term

The document contains 10 questions and answers related to writing JavaScript programs. Each question asks the programmer to write code to perform a specific task like accepting user input, performing calculations, and printing output. The answers provide the code to complete each task in 1-2 paragraphs of JavaScript code within HTML tags.

Uploaded by

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

Web App Mid Term

The document contains 10 questions and answers related to writing JavaScript programs. Each question asks the programmer to write code to perform a specific task like accepting user input, performing calculations, and printing output. The answers provide the code to complete each task in 1-2 paragraphs of JavaScript code within HTML tags.

Uploaded by

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

Q1.

WRITE A PROGRAME TO ACCEPT YOUR AGE AND YEAR OF SERVICE


AND PRINT THEM IN SEPARATE LINES?

Ans:- <html>

<body>
<script>
var age= prompt("enter the age");
var year= prompt("enter your year of service");
document.write("the age is"+ age+"<br>");
document.write("the year is"+ year);
</script>
</body>
</html>
_____________________________________________________________________________________
Q2. WRITE A PROGRAME TO ACCEPT TWO NUMBERS AND CALCULATE
THEIR PRODUCT?

Ans:- <html>
<body>
<script>
var n= prompt("enter the 1st number");
var m= prompt("enter your 2nd number");
var p= n*m;
document.write("the product is"+p);
</script>
</body>
</html>
_____________________________________________________________________________________
Q3. WRITE A PROGRAME TO ACCEPT THE PRINCIPLE AMOUNT,TIME AND
RATE PERCENTAGE AND PRINT THE SIMPLE INTREST IN AN ALERT?

Ans:- <html>
<body>
<script>
var l= prompt("enter the principle amount");
var m= prompt("enter the time");
var n= prompt("enter the rate percentage");
var o=(l*m*n)/100;
window.alert("the product is"+o);
</script>
</body>
</html>

_____________________________________________________________________________________
Q4. WRITE A PROGRAME TO ACCEPT YOUR BASIC SALARY AND
CALCULATE THE NET SALARY AFTER APPLYING THE FOLLOWING?

(a) HRA 10%


(b) DA 5%
(c) HA 15%
(d) TAC 10%

HINT:- (NET SALARY =(BASIC SALARY+HRA+DA+HA)=TAX)

ANS:- <html>

<body>

<script>

var a=parseInt (prompt("enter the basic salary"));

var b=(10/100)*a

var c=(5/100)*a

var d=(15/100)*a

var e=(10/100)*a

var f=(a+b+c+d)-e;

document.write("the net salary is "+f);

</script>
</body>

</html>

_____________________________________________________________________________________
Q5. WRITE A PROGRAME TO ACCEPT A NUMBER AND CHECK WHETHER IT
IS POSITIVE OR NEGATIVE?

ANS:- <html>
<body>
<script>
var a=prompt("enter the number");
if(a>0)
{
document.write("the number is positive");
}
else
{
document.write("the number is negative");
}
</script>
</body>
</html>

_____________________________________________________________________________________
Q6. WRITE A PROGRAME TO ACCEPT YOUR MARKS AVERAGE AND PRINT
YOUR GRADE?

ANS:- < html>

<body>

<script>

var a=prompt("enter your marks");

if(a>50)

{
document.write("fair");

else if (a<40)

document.write("fail");

else(a>40)

{
document.write("pass");

</script>

</body>

</html>

_____________________________________________________________________________________
Q7. WRITE A PROGRAME TO ACCEPT THE DISTANCE TRAVELLED BY THE
CONSUMER AND CALCULATE THE TOTAL PAYMENT ACCORDING THE
FOLLOWING CRITERIA?

DISTANCE(KM) AMOUNT/KM

<5 RS. 5

5-10 RS.7

11-20 RS.10

>50 RS.15

ANS:- <html>

<body>

<script>

var a=prompt("enter your distance");

if(a<5)

document.write("the amount is Rs "+ (a*5));

else if ((a>5)&&(a<10))
{

document.write("the amount is Rs " + (a*7));

else if ((a>11)&&(a<20))

document.write("the amount is Rs "+(a*10));

Else

document.write(" the amount is Rs "+(a*15));

</script>

</body>

</html>

_____________________________________________________________________________________
Q8. WRITE A PROGRAME TO ACCEPT YOUR THREE SUBJECT MARKS AND
CALCULATE THE AVERAGE AND ALSO PRINT THE GRADES ACCORDING TO
THE FOLLOWING?

AGE GRADE

<40 F

41-50 C

51-60 C+

61-70 B

71-80 B+

81-90 A

>90 A+

ANS:- <html>

<body>

<script>

var english=prompt("enter your english marks");

var maths= prompt("enter your math marks");

var computer=prompt("enter your computer


marks");
var average=(english+maths+computer)/3;

if(average<40)

document.write("the grade is F");

else if((average>41)&&(average<50))

document.write("the grade is C");

else if((average>51)&&(average<60))

document.write("the grade is C+");

else if((average>61)&&(average<70))
{

document.write("the grade is B");

else if((average>71)&&(average<80))

document.write("the grade is B+")

else if((average>81)&&(average<90))

document.write("the grade is A");

else(average>90)

document.write(" the grade is A+");


}
</script>

</body>

</html>

_____________________________________________________________________________________
Q10. WRITE A PROGRAME TO ACCEPT THE DAY OF A WEEK IN NUMBER
AND PRINT WHICH DAY IT IS?

ANS:- <html>
<body>

<script>

var day = prompt("enter the number")

switch (day)
{
case '1': document.write("monday<br />");
break;

case '2': document.write("tuesday<br />");


break;

case '3': document.write("wednesday<br />");


break;
case '4': document.write("thursday<br />");
break;

case '5': document.write("friday<br />");


break;
case '6': document.write("saturday<br />");
break;
case '7': document.write("sunday<br />");
break;

default: document.write("Unknown day<br


/>")
}

</script>
</body >
</html >

_____________________________________________________________________________________

You might also like