# Eval Math.roundup or alternative method

So, I’m pretty green at this, but I’ve been tasked with making a command that lets people know they can do something for a certain amounts. This is what I came up with:
If you donate \$\$(touser), \$(touser)00 bits, or gift 1 sub, you can do the thing we’re talking about!

Super easy, I can just put a number in and it will input for the number I want. Except, now what we’re looking for is at 5 or less, its 1 sub, 6-10 is 2 subs, etc. The idea is that we don’t necessarily want to count up every time we do it, but it will count up every time someone does the thing.

The easiest way I can think of is just having it eval input/5 and round up, but I don’t think that’s something Nightbot recognizes. What is the best way to handle this?

Hey @gympy88!

First of all, have a look at the variable list, you’ll learn that what you want to use isn’t `\$(touser)`, but either `arguments` or `\$(query)`.

Next, I’m sorry, but I don’t understand what you want…

Except, now what we’re looking for is at 5 or less, its 1 sub, 6-10 is 2 subs, etc.

What does that mean? 5 or less what? The example following doesn’t help understanding either.

We’re not in your head, we can’t guess, so try to be as clear and as precise as possible when you describe your issue, in short: be specific, otherwise we can’t help, thank you in advance.

1 Like

Sorry about the vagueness. The “5” in question is the input. So the idea here is when I use “!thing 5”, it produces “If you donate \$5, 500 bits, or gift 1 sub”. If I do “!thing 6”, it produces “If you donate \$6, 600 bits, or gift 2 sub”, at 11 it produces “If you donate \$11, 1100 bits, or gift 3 sub”, etc.

Thanks for the clarification on \$(query). I’m still pretty green at programming nightbot, so I just used something the only thing I knew would insert something there, but obviously using the correct variable would be helpful in getting it to work.

@gympy88 Heya, your English is weird, to be honest.

``````!addcom -cd=5 !thing \$(eval `If you donate \$` + `\$(1)` + `,` + `\$(1)` + `00 bits, or gift ` + ( \$(1) - 4 ) + `sub`)
``````
``````!addcom -cd=5 !thing \$(eval a=`\$(1)`; if ( a === `5` ) { `If you donate \$5, 500 bits, or gift 1 sub` } else if ( a === `6` ) { `If you donate \$6, 600 bits, or gift 2 sub` } else if ( a === `11` ) { `If you donate \$11, 1100 bits, or gift 3 sub` } )
``````

I don’t know what you actually want. As you instructed, I coded like that. Hope it will work

1 Like

Thank you for the help. I know its not super clear, I don’t know exactly how to explain it. I appreciate the all the help, though.

So, I’m hoping to have something where when I do !thing (1-5), I get
If I do !thing (6-10), I get
\$(1-6), (6-10)00 bits, 2 gift subs
!thing (11-15) gets
\$(11-15), (11-15)00 bits, 3 gifts subs.

I’m really sorry for not being better about communicating this. And I really appreciate the effort and help I’m getting.

Thank you for taking more time to explain, I now understand what you’re looking for!

So the command would be the following:

``````\$(eval a=`\$(1)`; isNaN(a)?`Wrong input: use numbers only.`:`If you donate \$\${a}, \${a}00 bits, or gift \${Math.ceil(a/5)} subs, you can do the thing we're talking about!`;)
``````

If you’re curious to know why I used `Math.ceil()` and not `Math.round()`, I linked the documentation.

2 Likes

Thank you so much! I really appreciate it. Sorry for the mess I created with my earlier posts!

1 Like

No worries, it’s all good, we managed to sort it out!

1 Like

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