I have encountered an issue where I am trying to multiply two numbers and add another number, but the output is displaying as NaN. How can I troubleshoot and solve this problem?
Below is the code snippet:
medicines = [new Medicine()];
this.sum = 0;// sum variable is also of type number
for (let i = 0; i < this.medicines.length; i++)
{
this.sum = this.sum + this.medicines[i].price * this.medicines[i].quantity;// both price and quantity are of type number
console.log(typeof this.sum);// however, it prints NaN
}
Model for medicines:
export class Medicine{
constructor(){}
name: String;
quantity: number;
price: number;
}