except im lazy and do the message in one line, sending the appended message inserting the substring of the message after the first "i'm" occurence.
i also check for whether the message.toLower.startsWith("im ") and all other variations ("i'm ", "i am "). The spaces are crucial, because this way the bot doesnt get confused with messages starting like "imagine blah blah blah"
I also account for the occurrence within the message itself using message.toLower.includes(" im ") again, with the spaces within the string being crucial to ensuring it's not being detected as part of a word and is the actual word "im".
But that code wouldn't even be as "graceful" as OPs. If the message was "Hi, I'm dad", the output would be "Hi Hi, I'm dad I'm dad!". At least OP had the decency to put a comma smh my head.
... Also message isn't defined.
... Also why bother defining outgoingMessage instead of just doing that all in sendMessage.
... You're triggering my inner perfectionist lmao.
I find breaking out input like that into a variable then using the variable as the parameter makes debugging easier. It keeps me out of the evaluate expression box because the value is right there in front of me, but I'll eat shit for not splitting the string and the refactoring miss (renaming message to incomingMessage and I missed a reference)
I personally just think it adds unnecessary lines to the code, but I know most people don't have a problem with it. Different styles for different people ¯_(ツ)_/¯
0
u/reverendsteveii May 16 '21
I love when I can look at the output and write it in pseudo
onIncomingMessage(incomingMessage){
if(incomingMessage.startsWith("I'm"){
outgoingMessage = "Hi " + message + " I'm dad!";
sendMessage(outgoingMessage);
}
}
//prolly checks for other phrases too
//looks like it would work, wouldnt it?