runLab
объекта в массиве arrayOfObjects
. Пробовал сам не выходит. Подскажите как реализовать.const arrayOfObjects = [
{
student: 'Dmitriy',
runLab () {
return 1;
}
},
{
student: 'Andrew',
runLab () {
return 2;
}
},
{
student: 'Mellisa',
runLab () {
return 3;
}
},
{
student: 'Ann',
runLab () {
return 4;
}
},
];
function gradeLabs() {
arrayOfObjects.forEach((element) => element.runLab(), () => {
if (element.runLab !== 1) {
console.log(element.runLab());
}
})
}
gradeLabs();
arrayOfObjects.forEach((element) => element.runLab(), () => {
if (element.runLab !== 1) {
console.log(element.runLab());
}
})
arrayOfObjects.forEach((element) => {
const resultLab = element.runLab();
if (resultLab !== 1) {
console.log(resultLab);
}
});
const arrayOfObjects = [
{ student: 'Dmitriy', runLab () {return 1;}},
{ student: 'Andrew', runLab () {return 2;}},
{ student: 'Mellisa', runLab () {return 3;}},
{ student: 'Ann', XrunLab () {return 4;}},
];
function gradeLabs(labs, expectedResult = 1) {
labs.forEach(({ student, runLab }) => {
try {
const result = runLab();
if (result === expectedResult) {
console.log('Student %s has PASSED the test', student);
} else {
console.error('Student %s has FAILED the test', student);
}
} catch (e) {
console.error('Student: %s has FAILED the test. Error thrown: %o', student, e);
}
});
}
gradeLabs(arrayOfObjects, 1);