简体   繁体   中英

Logic not evaluating correct - Angular11

I got method to setRemark to display message passed or failed based on grade

Elementary grade = 75 is passed College grade = 3 is passed

   private getFinalGrade(studentId: number, gradingSections: IGradingSection[], transmutation: ITransmutation) {
        let finalGrade: number = 0;
        let grades: number[] = [];
        let gradingSectionNumber = gradingSections.length;
        for (let gradingSection of gradingSections) {
            let weightedPercentageGrade = (new StudentGradeComputerService(studentId))
                .setAssessment(gradingSection.assessments)
                .setTransmutation(transmutation)
                .generate()
                .getTotalWeightedScore();
            grades.push(weightedPercentageGrade);
            finalGrade += weightedPercentageGrade;
        }
        return {grades, finalGrade: finalGrade / gradingSectionNumber};
    }
    
    private setRemark(grades: number, removalGrade: number) {
        if(removalGrade) {
            grades = removalGrade;
        }
        let passingGrade = (grades < 6) ? 3 : 75;
        let condition = (passingGrade == 3) ? (grades <= 3) : (grades >= passingGrade);
        console.log(condition)
        return (condition && grades != 0) ? "Passed" : "Failed";
    }

UPDATED here's where i call setRemark

private getStudentScheduleBySession(studentRecord): void {
        let studentReportData: object[] = [];
        let maxGradingSections: number = 1;
        studentRecord.forEach((subject) => {
            let newData = subject;
            let grades = this.getFinalGrade(subject.student_id, subject.schedule.class_record.sections, subject.schedule.class_record.transmutation);
            newData["finalGrade"] = grades.finalGrade;
            newData["grades"] = grades.grades;
            newData["remark"] = this.setRemark(newData["final_grade"], newData["removal_grade"]);
            studentReportData.push(newData);

            maxGradingSections = (grades.grades.length > maxGradingSections) ? grades.grades.length : maxGradingSections;
        })
        this.maxGradingSections = maxGradingSections;
        this.studentReportData = studentReportData;
    }

The problem is even the grade is 70 its still showing passed. I don't know what's the problem with my logic.

在此处输入图像描述

As per the code snippet for getStudentScheduleBySession method, u stored the value of new grade in to newData["finalGrade"]. But in setRemark method passing variable name is newData["final_grade"]. I think it should be newData["finalGrade"].

I've solved it the problem was this line

newData["remark"] = this.setRemark(newData["final_grade"], newData["removal_grade"]);

It's not passing data so change to this

newData["remark"] = this.setRemark(grades.finalGrade, newData["removal_grade"]);

Thanks everyone for giving me more hints to debug.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM