Write a script to accept marks of student and calculate average. Enter- 1 to end the sequence of marks.
<HTML>
<HEAD>
<TITLE>
Class Averge Program
<TITLE>
<SCRIPT LANGUAGE=”JavaScript”>
Var grade Counter
Gradevalue,
Total,
Avg,
Grade;
Total=0;
Grade Counter=0;
Grade=[Link] (“Enter integer Grade, -1 to Quit:””0”);
Grade value=parselnt (grade);
While (gradevalue! =-1)
Total=total+gradevalue;
Grade Counter=gradeCounter+1;
Grade= [Link] (“Enter lnteger Grade is “+avg+<HI>”);
Grade value = parselnt (grade);
If (grade Counter! =0)
{
Avg=total/grade counter;
[Link] (“<HI>Class average is “+avg+”<HI”);
Else
[Link] (“P>No grades were entered</P>”);
</SCRIPT>
</HEAD>
<BODY><P>Refresh to run the script again</P></BODY>
<HTML>
Output
10. Write a script to analye the examination resuits.
<HTML>
<HEAD>
<TITLE>
Analysis of Examinations Results
</TITLE>
<SCRIPT LANGUAGE=”JavaScript”>
Var pass=0.
Fail=0.
Student=1,
Result;
While (student<10)
Result=[Link] (“Enter result (1=pass, 2=fail)”, “0”);
If (result==”1”)
Pass =pass+1;
Else
Fail=fail+1;
Student=student+1;
[Link] (“<P><HI>Examinations Results</HI></P>”);
[Link] (“Passed;”+pass+”<BR>Failed;”+fail);
</SCRIPT>
</HEAD>
<BODY><P>Refresh to run the script again</P></BODY>
</HTML>
(A) Increment and decrement OPERATORS
JavaScript provides several assignment operators for abbreviating assignment expressions. The
statement
C = C+3; can be written as C + = 3;
C = C- 3; can be written qas C - = 3;
C = C * 3; can be written as C * = 3;
C =C/3; can be written as C/ = 3;
C = C % 3; can be written as C % = 3;
(B) Increment and Decrement Operators
JavaScript provides the unary increment operator (++0 and decrement operator (- -). The
stestment
C = C + 1; can be written as C ++; or ++C;
C = C – 1; can be written as C --; or –C
(11) Write a script to demonstrete assignment increment, and decrement operators.
<HTML>
<HTML>
<TITLE>Preincrementing and Postincrementing</TITLE>
<SCRIPT LANGUAGE = “JavaScript”)
Var c;
c =5;
[Link] (“<H3>Postincrementing</H3>”);
[Link] (c); //print 5
[Link] (“<BR>” = C ++); // print 5 them increment
[Link] (“<BR>” +C); // Prient 6
C = 5;
[Link] (“<H3> Preincrementing</H3>”);
[Link] (C); // PRIENT 5
[Link] (“<BR>” + + + C); // increment then prient 6
[Link] (“<BR>” + C); // prient 6
</SCRIPT>
</HEAD><BODY></BODY>
</HTML>
Output
(c) Essentials of Counter-Controlled Repetition
Counter-control repetition requies
1. The “name” of the control variable (or loop counter).
2. The “initial value” of the countrol variable.
3. The “increment” (or decrement) by which the control variable is modified each time
though the loop.
4. The “condition” that tests for the final value of the contrl variable to determine
whether looping should contine.
[Link] The “for” Repetition Structure
The “for” repetition structure handles allthe details of counter-controlled repetition. Syntax;
For (initialization; test; increment / decrement)
Code