3. Create an object student with properties: name (string), grade (number), subjects (array), displayInfo() (method to log the student’s details) Write a script to dynamically add a passed property to the student object, with a value of true or false based on their grade. Create a loop to log all keys and values of the student object.
PROGRAM:
let student = {
name: "John Doe",
grade: 85,
subjects: ["Math", "Science", "English"],
displayInfo: function() {
console.log(`Name: ${this.name}`);
console.log(`Grade: ${this.grade}`);
console.log(`Subjects: ${this.subjects.join(', ')}`);
}
};
student.passed = student.grade >= 50;
student.displayInfo();
for (let key in student) {
if (typeof student[key] !== 'function') {
console.log(`${key}: ${student[key]}`);
}
}
Step 4: To run program use below command:
- Open the vscode integrated terminal through the menu by selecting and type the below command to run the program.
node index.js
OUTPUT:
Name: John Doe
Grade: 85
Subjects: Math, Science, English
name: John Doe
grade: 85
subjects: Math,Science,English
passed: true