Hi @mohkanaan,
Your solution works, but, apart from the require() statement, your updateBalance function is performing the same operation as the addUser function: it’s creating a whole new User
instance. We only need to do that when we add a new user, because once added, their user ID won’t need to change (at least not at the same time as their balance).
So what you want to aim for with the updateBalance function, is code that only updates the balance
property for a particular user ID, and not the whole User
instance.
In terms of your require() statement, preventing zero amounts being input would certainly make sense if the updateBalance function was adding these amounts to the user’s existing balance. However, instead, the function is replacing the user’s existing balance with a new one. The addUser function doesn’t contain the same require() statement, so do you really want to allow new users to be added with zero balances, but prevent existing balances being reduced to zero?
I assume you’ve already seen the 2 alternative solutions suggested in the follow-up video. Can you see how they are more suitable?
Let me know if anything is unclear, or if you have any questions 