The evaluation of the logic in Angular11 is not yielding accurate results

I have developed a method called setRemark which displays a message indicating whether the grade passed or failed

According to the method: Elementary grade = 75 is considered as "passed" College grade = 3 is also considered as "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 is where the setRemark method is being called

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;
    }

Even when the grade is 70, it still shows as "passed". There seems to be an issue with my logic that needs fixing.

https://i.sstatic.net/BKfWp.png

Answer №1

After reviewing the getStudentScheduleBySession method code snippet, it appears that you are storing the new grade value in newData["finalGrade"]. However, in the setRemark method, the variable name being passed is newData["final_grade"]. It seems that there may be a typo and it should actually be newData["finalGrade"].

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Show the subscription response data in Angular

When utilizing the code snippets below from two different components, I am able to receive a valid response value from the subscriber. dataService.ts fetchFormData(){ return this.http.get('http://localhost:48116/RecuruitmentService.asmx/addRoleTest ...

Encountering an issue in Angular where data.slice is not functioning properly, resorting to using parseInt to convert strings into Date

Looking to convert the data retrieved from the database into numbers and dates with ease. One set of data is in milliseconds while the other is in timestamps. https://i.stack.imgur.com/HdM0D.png The goal is to transform both types into numbers first, the ...

Is there a way to utilize req.query, req.params, or req.* beyond its original scope without the need to store it in a database?

Looking to streamline my code and apply the DRY pattern, I've been working on creating a helper function for my express http methods. The structure of each method is similar, but the req.params format varies between them. Here's how I attempted t ...

Angular expands the HTML of the parent component

Although this question may be old, I am still struggling to find a straightforward answer and it just doesn't make sense to me. I have a main component with its own HTML and several components that inherit from it. Here is what I am trying to achiev ...

The 'bind' property is not found within the 'void' data type

Here's the code snippet I'm working with: setInterval(this.CheckIfCameraIsAvailable(false).bind(this), 2 * 60 * 1000); private CheckIfCameraIsAvailable(forceCheck: boolean) { } I encountered the following error message: Property 'bin ...

When accessing from the frontend (Angular), the User.FindFirst(ClaimTypes.NameIdentifier) method does not return any values

I'm encountering a new issue - just as the title suggests. I've managed to identify where the problem occurs but I'm unable to resolve it. Let's start from the beginning. In the backend (ASP.NET 3.0), I have a class AuthController with ...

Issue with Angular router failing to load the correct component

As a novice with Angular, I have the following routes set up. app.routing.module.ts import { NgModule } from '@angular/core'; import { RouterModule } from '@angular/router'; import { FrameComponent } from './ui/frame/frame.compon ...

How to Utilize Class Members in a Callback Function in Angular 12 with Capacitor Version 3

When I click the "Device Hardware Back Button" using Capacitor 3.0, I'm trying to navigate to the parent component with the code below. The device back button is working correctly, but I'm facing an issue where I can't access class members i ...

What specific event do I require for the onChange event in React using TypeScript?

I'm facing a problem while working with React TypeScript. I need to type the onChange event for a select element, but the data is coming from event.value instead of event.target.value. What should be the appropriate event to use in this case? Below i ...

Is there a way for me to trigger an action based on the Observable's return

I'm eager to optimize this by implementing observables: post<T>( url: string, body: any, params?: HttpParams, headers?: HttpHeaders ): Observable<T> { this.isLoading$.next(true); const res = this.http .p ...

How can I remove a row from a mat table using Angular?

Having trouble implementing *ngFor in my angular mat table, seeking guidance from someone with more expertise? I am trying to delete a row within an array using a button and display it on my table, but encountering issues. I intend to utilize *ngFor to sh ...

Is it possible to use both interfaces and string union types in TypeScript?

My goal is to create a method that accepts a key argument which can be either a string or an instance of the indexable type interface IValidationContextIndex. Here is the implementation: /** * Retrieves all values in the ValidationContext container. ...

Issues encountered while attempting to use 'npm install' on Angular, leading to

Having trouble with npm i in my project. It's not working for me, but others can install it smoothly. I've checked all the node and angular versions, but I can't figure out what's missing. Could it be my laptop's compatibility? Ple ...

How can two components share the status of their side bar being open or closed?

I am currently working on a project using React and TypeScript. My setup is displayed below, where I have a button in the "Topbar" that, when clicked, should minimize both the sidebar and elements on the left side of the Top Bar. How can I properly pass ...

Maximizing Performance: Enhancing Nested For Loops in Angular with Typescript

Is there a way to optimize the iteration and comparisons in my nested loop? I'm looking to improve my logic by utilizing map, reduce, and filter to reduce the number of lines of code and loops. How can I achieve this? fill() { this.rolesPermiAdd = ...

The functionality of external linking seems to be malfunctioning within Angular 2

Take for instance the website: The routing system is in place so that when you click on pages or links, the URL changes to something like: /articles /work /articles/1 However, if you were to click on this link: A 404 error is thrown. How can I configur ...

Filtering function that works without specific knowledge of keys

I'm working on a JavaScript method to filter a list dynamically without knowing the specific key (s). I've made some progress, but I'm stuck and not sure how to proceed. The foreach loop I have isn't correct, but I used it for clarity. ...

Tips for resolving the issue of the symbol ' displaying as &#39 in an Angular 2 application

I am currently working on an Angular application that makes API calls when a name displayed in a grid table is clicked. However, I have encountered an issue where names containing an apostrophe are being displayed incorrectly as &#39 instead. I managed ...

When handling a document click event in Typescript, an error may occur where it cannot read

Just starting out with Typescript and diving into Angular, I am currently in the process of converting my project to the Angular system. However, I've hit a roadblock. I need to figure out how to close the dropdown content when the user clicks anywher ...

When the admin clicks the start button, redirect all users to the designated page

Currently, I am developing a voting application that features both an admin and users. My goal is for the voting campaign to kick off as soon as the admin clicks on the start button. Upon starting the voting process, I aim to redirect all users to a diff ...