Apologies for the repetitive question, but I am really struggling to find a solution. I am facing an issue with this calculation. The parameters a to g represent the values of my input from the HTML. I need to use these values to calculate a sum. When I try console.log(+this.a), it gives me a number. However, console.logging(this.aa) results in NaN. Can someone please guide me on how to address this problem? Thank you.
Here is a snippet from my TypeScript file:
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
@IonicPage()
@Component({
selector: 'page-song',
templateUrl: 'song.html',
})
export class SongPage {
a:string;aa:number = +this.a * 2;
b:string;bb:number = +this.b * 7;
c:string;cc:number = +this.c * 6;
d:string;dd:number = +this.d * 5;
e:string;ee:number = +this.e * 4;
f:string;ff:number = +this.f * 3;
g:string;gg:number = +this.g * 2;
sumA:number = (this.aa+this.bb+this.cc+this.dd+this.ee+this.ff);
sumB:number = this.sumA%11;
sumC:number = 11-this.sumB;
char: string;
constructor(public navCtrl: NavController, public navParams: NavParams) {
}
cal()
{
console.log(this.aa);
if(this.sumC == 1)
{
this.char = 'A';
}
else if(this.sumC == 2)
{
this.char = 'B';
}
else if(this.sumC == 3)
{
this.char = 'C';
}else if(this.sumC == 4)
{
this.char = 'D';
}else if(this.sumC == 5)
{
this.char = 'E';
}else if(this.sumC == 6)
{
this.char = 'F';
}else if(this.sumC == 7)
{
this.char = 'G';
}else if(this.sumC == 8)
{
this.char = 'H';
}
else if(this.sumC == 9)
{
this.char = 'I';
}else if(this.sumC == 10)
{
this.char = 'Z';
}else if(this.sumC == 11 || 0)
{
this.char = 'J';
}else
{
this.char = 'NaN';
}
}
}
And here is the relevant part from my HTML file:
<ion-input name="two" class="box" maxlength="1" [(ngModel)]="a"></ion-input>
<ion-input name="three" class="box" maxlength="1" [(ngModel)]="b"></ion-input>
<ion-input name="four" class="box" maxlength="1" [(ngModel)]="c"></ion-input>
<ion-input name="five" class="box" maxlength="1" [(ngModel)]="d"></ion-input>
<ion-input name="six" class="box" maxlength="1" [(ngModel)]="e"></ion-input>
<ion-input name="seven" class="box" maxlength="1" [(ngModel)]="f"></ion-input>
<ion-input name="eight" class="box" maxlength="1" [(ngModel)]="g"></ion-input>
<button ion-button round block (click)="cal()">Validate</button>
<h2>The character is: {{char}}</h2>