The document contains code snippets that demonstrate using JavaScript prompts and conditional statements. The first code takes user input for exam marks and uses if/else statements to output the grade. The second takes user input for a year and uses logic to determine if it is a leap year. The third is incomplete code that aims to take user input for maximum marks and marks obtained, calculate the percentage, and output encouragement or advice based on the percentage.
1 of 4
Download to read offline
More Related Content
Refresher
1. Refresher lesson- Wordsearch
R X L
D
Z
S
F H T
W
K
T
I D P
R
U
I
E I E
W
G
Y
T I Y
C
K
O
J R G
I
I
E
L A A
P
N
S
GJ L
H
F
P
E
V
R
C
G
W
C
O
A
L
C
F
E
Q
I
S
L
O
A
I
C
K
G
Y
X
P
E
K
H
X
K
O
B
A
I
R
A
T
S
Z
S
H
U
D
G
N
T
P
P
P
O
Z
T
M
Z
I
S
U
K
A
T
C
O
L
V
C
G
G
L
I
N
E
2. What do the following codes do?
<html>
<body>
<script type="text/javascript">
var marks = prompt("enter the marks of test","");
marks=parseInt(marks);
if(marks>=60)
{
document.write("grade is a");
}
else if (marks >=45)
{
document.write("grade is b");
}
else
{
document.write("grade is f");
}
</script>
3. What do the following codes do?
<html>
<body>
<script type="text/javascript">
var yr = prompt("enter the year","");
yr=parseInt(yr);
if (yr%4==0 && yr%100!=0 || yr%400==0)
{
document.write ("YEAR",yr,"is a leap year");
}
else
{
document.write ("YEAR", yr," is not a leap year");
}
</script>
</body>
</html>
4. Make the following code work
<html>
<body>
<script type="text/j">
var maxmarks = prompt("enter the max marks of test","");
var marks = prompt("enter the marks of test","");
maxmarks=p(maxmarks);
marks=parseInt(marks);
var percen=marks/maxmarks*100
if(percen>80)
{
document.write("you have",percen,"% in this test");
document.write("<PRE>nCongratulations for your performance </PRE>");
}
else
{
document.write ( you need to work a little more for excellence");
document.write ("<PRE>nPlan better and you will be there</PRE>");