Skip to content

Conversation

xiaowei-zhang
Copy link
Contributor

Add one more condition to trigger accurate error messages

Add one more condition to trigger accurate error messages
Comment on lines +118 to +122
* if (0 <= amount && amount <= balance) {
* balance = balance - amount
* balance
* } else if (amount < 0) {
* throw new Error("invalid withdraw amount")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since, to me, it doesn't make sense to withdraw 0.

Suggested change
* if (0 <= amount && amount <= balance) {
* balance = balance - amount
* balance
* } else if (amount < 0) {
* throw new Error("invalid withdraw amount")
* if (0 < amount && amount <= balance) {
* balance = balance - amount
* balance
* } else if (amount <= 0) {
* throw new Error("invalid withdrawal amount")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants