I am in the process of developing a Shopping Card feature.
private _card: Map<Product, number> = new Map<Product, number>();
...
addToCard(prod: Product, amount: number = 1): void {
const totalAmount: number = this._card.get(prod) + amount; // Calculating the total amount
console.log(this._card.get(prod) + ' + ' + amount);
this._card.set(prod, totalAmount);
}
Log:
card.service.ts:31 0 + 1
card.service.ts:31 01 + 1
card.service.ts:31 011 + 2
card.service.ts:31 0112 + 2
card.service.ts:31 01122 + 3
card.service.ts:31 011223 + 4
It seems that instead of performing normal addition, the result is being concatenated. I have verified that all variables are declared as numbers.
Thank you for any assistance provided.