Professional Documents
Culture Documents
Gr. 8 - Count - Asynchronous Task - 12th October 2021
Gr. 8 - Count - Asynchronous Task - 12th October 2021
GRADE 8
Learning Intention : To develop efficient codes using accumulator
in the looping concept in JavaScript.
Success Criteria :
✓ Know the syntax of for…loop for the looping concept.
✓ Understand how accumulator can be used to find the count.
✓ Develop & execute the code to display the sum and count using
accumulator and For loop.
✓ Trace the output for the given for…loop structure.
RECAP
An accumulator is a variable
that the program uses to
calculate a sum or product of a
series of values. A computer
program does this by having a
loop that adds or multiplies
each successive value onto the
accumulator.
An eg. Adding the values
12,7,9,10
What is the difference between sum
and count?
SUM is the process of adding of numbers. It answering
the question: HOW MUCH? Or, WHAT IS THE
TOTAL?
SUM : COUNT :
<script> <script>
for(var a=1,s=0;a<=5;a++) for(var a=1,c=0;a<=5;a++)
{ {
s= s + a; c= c + 1;
} }
alert("Summation = " +s) alert(“Count = " +c)
</script> </script>
Write the program code & dry run to find the sum of
numbers from 1 to 5.
</script>
</body> </html>
Write the program & dry run to accept the computer marks of 3 students. Calculate
and display the total marks of the 3 students and display the number of students
getting 100.
<script>
for(var a=1,s=0,c=0,m=0;a<=3; a++)
{
m=+prompt(“Enter your marks”);
s=s+m;
if(m==100)
c= c + 1;
}
alert(“Total= ” + s);
alert(“Count= ” +c);
</script>
Write the program & dry run to accept the computer marks of 3 students. Calculate
and display the total marks of the 3 students and display the number of students
getting 100.
Dry Run : Assume m=100, 98, 95
<script>
a a< m s=s+m m= c=c+ Output a++
var s=0,c=0,m=0; =3 =10 1 (Alert)
for(var a=1;a<=3; a++) 0
{ 1 T 100 0+100= T 0+1 1+1=2
m=+prompt(“Enter your marks”); 100 =1
s=s+m; 2 T 98 100+98 F 1 3
if(m==100) =198
c= c + 1; 3 T 95 198+95 F 1 4
} =293
alert(“Total= ” + s); 4 F Total=293
alert(“Count= ” +c); Count=1
</script>
Assess your Learning
Write the program & dry run to accept the cost of 4 items
purchased by the user. Calculate and display the total cost and
display the number of items costing 50dhs or more.
<!doctype html>
<html>
<head> <title>JS</title> </head>
<body>
<h1 style="text-align:center;"> Cost of Items </h1>
<script>
</script>
</body> </html>
Assess your Learning