Skip to content
Advertisement

Not combining values in deposit command, using discord.js

I’m adding a deposit command but when I try to add the amount into the bankBalance, it doesn’t add them correctly into integers, this may sound confusing, I’ll give you an example.

Example:

Command: ~deposit 100, User balance: Wallet: 120, Bank: 0, Output user balance: Wallet: 20, Bank: 0100

I wish this explains it, anyways here is my code:

JavaScript

Note: I’m using replit

Advertisement

Answer

In your case, either the bankBalance or amount variable is a string causing them to both be converted into a string then appended to each other. A solution would be to use the parseInt function to convert both values to a number.

Example:

JavaScript

Full Example:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement