Hi @patgeek,
If you had only included this line of code in your updateBalance() function body, then your contract would have compiled and solved the task.
Your idea of including an assert statement to check the new balance is perfectly OK, but the condition needs an equality comparison operator (==
) instead of an assignment operator (=
). If you make this modification, your contract will now compile and work as you intend.
Even though the initial idea of this assignment is to update the existing balance by replacing it with the new one, I actually think that it does make more sense to do what you’ve done, and add an amount to the user’s existing balance using the addition assignment operator +=
(instead of the assignment operator =
).
However, if we add to, instead of replacing, the existing balance, I think the code looks clearer and more readable if we also change the name of the balance
parameter to amount
, because we are adding an amount to the balance (to give a new total balance), rather than replacing it with a new balance.
There is always more than one solution to these assignments, and alternative interpretations are equally valid.
Let us know if anything is unclear, or if you have any questions