How to print all students name having percentage more than 70% in JavaScript?

JavascriptWeb DevelopmentObject Oriented Programming

You can use a for loop and check whether the percentage is greater than 70 or not with if condition.

Following are the records of each student −

const studentDetails=
[
   {
      studentName:"John",
      percentage:78
   },
   {
      studentName:"Sam",
      percentage:68
   },
   {
      studentName:"Mike",
      percentage:88
   },
   {
      studentName:"Bob",
      percentage:70
   }
]

Now, use the for loop and et conditions for students with percentage more than 70 −

for(var index=0;index<studentDetails.length;index++)
   {
      if(studentDetails[index].percentage > 70)
      {
         //
   }
}

Example

const studentDetails=
[
   {
      studentName:"John",
      percentage:78
   },
   {
      studentName:"Sam",
      percentage:68
   },
   {
      studentName:"Mike",
      percentage:88
   },
   {
      studentName:"Bob",
      percentage:70
   }
]
for(var index=0;index<studentDetails.length;index++){
   if(studentDetails[index].percentage > 70){
      console.log("Student Name which has more than 70
      %="+studentDetails[index].studentName);
   }
}

To run the above program, you need to use the following command −

node fileName.js.

Here, my file name is demo68.js. This will produce the following output −

PS C:\Users\Amit\JavaScript-code> node demo68.js
Student Name which has more than 70 %=John
Student Name which has more than 70 %=Mike
raja
Published on 03-Sep-2020 07:40:00
Advertisements