I’m trying to create a cuteness command using eval, but I keep getting a “Right-hand side of ‘instanceof’ is not an object” when using this code

`!addcom !cuteness $(touser), on a scale of 1 to 10, you’re a solid $(eval n=Math.floor(Math.random() * Math.floor(11) + 1); if(n == 11) return Math.floor(Math.random() * Math.floor(11) + 1); else return n;)`

The code is supposed to give a number 1-11, but if it’s an 11, then it rolls one more time.

I’m not a coder so I’m just trying to help as I can. I’m just confused if the reroll on purpose? 1 to 10 but it’s 11? If not you can just do:`!addcom !cuteness $(touser), on a scale of 1 to 10, you’re a solid $(eval n=Math.floor(Math.random()*10+1))

Hey @ZhediKnight!

I assume the idea of re-rolling if `n=11`

is because you don’t want it to give an `11`

. You don’t need to test this as the code can’t give you an `11`

. And regarding the error you get, here’s how to fix it:

```
!addcom !cuteness $(eval `$(touser), on a scale of 1 to 10, you're a solid ${Math.floor(Math.random()*10+1)}!`)
```

Edit: Sorry, didn’t see With_Vince corrected it, I stopped at the first sentence because I wasn’t seeing the code at first glance. Anyway, you still have the explanation of why you don’t need to test for `n=11`

.

`Math.random()`

generates a random number between `0`

*inclusive* and `1`

*exclusive*.

So `Math.random()*10`

generates a random number between `0`

*inclusive* and `10`

*exclusive*.

Which means that `Math.random()*10+1`

generates a random number between `1`

*inclusive* and `11`

*exclusive*: you can get a number between `1`

and `10.99999`

, that’s why we use `Math.floor()`

to **round down** the generated number **to the nearest integer**.

So `Math.floor(Math.random()*10+1)`

will generate a random *integer* between `1`

and `10`

*inclusive*.

`Math.floor(Math.random()*11)`

will however generate a random *integer* between `0`

and `10`

*inclusive*.

Hello again,

My goal was to make it a 1-11, with 11 being extremely rare. I was trying to test for n=11 because that way, in order to display an 11, you would have to roll two 11s in a row. If you rolled a first 11, it would reroll and display whatever that number was instead. I.E. if it rolls an 8 the first time, it just displays that 8, but if it rolls an 11, so it rolls again and gets an 8, so it displays 8, and finally, if it rolls an 11, it rerolls, and gets an 11, so it displays an 11.

Oh, then that’s different, if you explained that in your first post you would have gotten the code you’re looking for on first try. Do be the most descriptive possible when you ask for help, it saves us time, thank you. Anyway, here’s what you’re looking for:

`!addcom !cuteness $(eval r=()=>Math.floor(Math.random()*11+1);a=r();`$(touser), on a scale of 1 to 10, you're a solid ${a==11?r():a}!`)`

Sorry about that. Thanks for all the help!

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