Help with custom JS commands

I’m trying to take a users text and change it to something else. I just dont fully understand the $eval() stuff. Here is what I have:

    ($eval var stringToAlter = 'test';var stringArray = stringToAlter.split('');var 
    alteredString;stringToAlter.forEach(s => {  if (s % 2 === 0) {    alteredString = alteredString + 
    s.toLowerCase();  }  else {    alteredString = alteredString + s.toUpperCase();  }});)

I’m trying to take the text and make every other word a capital letter to emulate the spongebob meme.

Thanks for any help!

Well firstly is should be $(eval) , also it looks like s is undefined.
I can just write out something that should work for you If you want or feel free to problem solve yourself up to you.

Sure if you’d like to!

Ok here this should work for your purposes

$(eval d="$(1)";a=`$(query)`.split(``);function Memify(a) {aOutput=``;for(b=0;b<a.length;b++) {c=Math.floor(b%2);if(c==0) {aOutput+=a[b].toUpperCase()} else {aOutput+=a[b].toLowerCase()}};return aOutput};d=="null"?"PlEaSe iNpUt sOmEtHiNg aFtEr !MeMe":Memify(a))

Hope this was helpful :slight_smile:
Edit: Made it so if there is not input it explains the command.

Thank you sooooooooooooooo much! You are amazing

1 Like

Hello again! I was just wondering if you could elaborate on some questions I have so I can code some others in the future without having to rely on help…


Can you tell me what $(1) does?
as well as the $(query)?

I’m guess they are parameters, but I can’t find any documentation anywhere (I’m probably looking in the wrong spots) of what they mean and what they do…

Thanks again!

They are nightbot variables you can find them on the help docs..
$(query) takes everything said after the command and $(1) only takes the first word (or whenever the first space comes)
The reason I used the $(1) is to test whether it’s null or not (I tried with $(query) but it didn’t output null for some reason)
And $(query) is just take everything said and then splitting it into an array

1 Like

OMG, this is perfect. Thank you so much for the elaboration and the helpful link!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.