DEV Community

Akash
Akash

Posted on

Array exercise in JS

  • Array stores multiple values in single variable
  • It can store any data type
  • It is dynamic in size(able to change values)

Let solve scenario question in array

1.Find Fail count,if fail count is > 0 print (NO GRADE), Find Total,Find Average,if avg>90 print GRADE A,if avg>80 print GRADE B,if avg>70 print GRADE C,if avg>50 print GRADE D,else print GRADE E

Solution:-

const marks=[60,80,31,58,92]
1.declare variables
let i=0;
let fail count=0
let total=0
let avg=0

  1. Declare condition while(i<=4) and if(marks[i]<35) 3.post increment fail count 4.post increment i 5.Add condition to check if(fail count>0) 6.print ("NO GRADE") 7.Add while condition to find total while(i<=4) i=0 total=mark[i]+total 8.Avg= total/no of subject 9.If avg>=90 print(A) if avg>80 and avg<90 print(B) if avg>70 and avg<80 print(C) if avg>50 and avg<70 print(D) else print(E)

Top comments (0)