You are on page 1of 6

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=window.prompt (“Enter integer Grade, -1 to Quit:””0”);

Grade value=parselnt (grade);

While (gradevalue! =-1)

Total=total+gradevalue;

Grade Counter=gradeCounter+1;

Grade= window.prompt (“Enter lnteger Grade is “+avg+<HI>”);

Grade value = parselnt (grade);

If (grade Counter! =0)


{

Avg=total/grade counter;

Document.writeln (“<HI>Class average is “+avg+”<HI”);

Else

Document.writeln (“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=window.prompt (“Enter result (1=pass, 2=fail)”, “0”);


If (result==”1”)

Pass =pass+1;

Else

Fail=fail+1;

Student=student+1;

Document.writeln (“<P><HI>Examinations Results</HI></P>”);

Document.writeln (“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;

Document.writeln (“<H3>Postincrementing</H3>”);

Document.writeln (c); //print 5

Document.writeln (“<BR>” = C ++); // print 5 them increment

Document.writeln (“<BR>” +C); // Prient 6

C = 5;

Document.writeln (“<H3> Preincrementing</H3>”);

Document.writeln (C); // PRIENT 5

Document.writeln (“<BR>” + + + C); // increment then prient 6

Document.writeln (“<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.
1.9.3.2 The “for” Repetition Structure

The “for” repetition structure handles allthe details of counter-controlled repetition. Syntax;

For (initialization; test; increment / decrement)

Code

You might also like