discord.js bot math not working right

So with my bot when someone purges a channel I want to add one to the purge amount they have then split the first value off so it doesn’t purge their command, However when I try to add 1 to the value of the argument passed it just puts the number behind the value… Any help, I’ really crappy at JS so ye…

if (args[1]){
    var messagecount = args[1];
    var messagetotal = Math.floor(messagecount + 1); // Adding 1 to passed argument
    console.log(messagetotal); // Outputting to console, Console is reading the argument with 1 on the end EX: arg: 2 | output: 21
//  message.channel.fetchMessages({limit: messagecount}).then(messages => message.channel.bulkDelete(messages).then(messages => message.channel.send("Purged `" + messages.size + "` messages.")));
} else {
//  message.channel.send("Usage: !purge (Number)");
}

Answer

I don’t know that the exact content of args[1] is, but regarding your explanation of the bug, it seems that the value is a number formatted as a string.

The difference:

String

args[1] = "1";
console.log(args[1] + 1);

Output: "11"

Integer

args[1] = 1;
console.log(args[1] + 1);

Output: 2

If you add a number to a string, it will be appended and not added mathematically.

To format your numeric string to an integer, replace

var messagecount = args[1];

through

var messagecount = parseInt(args[1]);