0
votes

How Can I Solve this?

code TS bellow:

this should be simple but im new to angular

is a simple page that calculates the average of students

import { Grade } from './calculator.model';
import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-calculator',
  templateUrl: './calculator.component.html',
  styleUrls: ['./calculator.component.css'],
})
export class CalculatorComponent implements OnInit {
  grade: Grade = {
    name: '',
    grade1: null,
    grade2: null,
    grade3: null,
  };

  constructor() {}

  ngOnInit(): void {}

  calcGrade(
    grade1: number,
    grade2: number,
    grade3: number,
    account: number
  ): void {
    account = (grade1 * 0.25 + grade2 * 0.25 + grade3 * 0.5) / 3;

    if (grade1 && grade2 < 6.2) {
      console.log('aluno repovado');
    }
  }
}

I tried put the params in the constructor but do not works

code HTML bellow

in html I just passed the function created in the component

<div class="container">
  <div class="header">
    Olá Professor
  </div>
  <form class="form" action="submit">
    <input
      [(ngModel)]="grade.name"
      type="text"
      class="inputName"
      placeholder="Nome do Aluno:"
    />
    <input
      [(ngModel)]="grade.grade1"
      type="number"
      class="inputGrade"
      placeholder="Nota da prova 1:"
    />
    <input
      [(ngModel)]="grade.grade2"
      type="number"
      class="inputGrade"
      placeholder="Nota da prova 2:"
    />
    <input
      [(ngModel)]="grade.grade3"
      type="number"
      class="inputGrade"
      placeholder="Nota da prova 3:"
    />

    <button (click)="calcGrade()" class="button">Calcular</button>
  </form>
</div>

1

1 Answers

0
votes

Your calcGrade function requires 4 arguments but when you call it in the HTML template you don't supply any.

Instead, remove the parameters from the function signature and access them from the ngModal object you created (grade) inside the function.

calcGrade() {
   account = (grade.grade1 * 0.25 + grade.grade2 * 0.25 + grade.grade3 * 0.5) / 3;

   if (grade.grade1 && grade.grade2 < 6.2) {
     console.log('aluno repovado');
   }

}