Command wont work

“Right-hand side of ‘instanceof’ is not an object”
$(eval var r = [Math.floor(Math.random()*10)]; var a = [“Bad”]; var c = [“Good”]; ? (r < 10) : (a) : (r == 10) : ©;)
I have tried make a command that roll the number between 1 - 10 after it should give an answer A or C, if rolled number equals 10 - A, if below 10 - C
nightbot responce: 1 from 10, A or C variant
I have tried many spellings already and don’t know what to try

Hey @nyawinthenight!

I fixed it for you:

$(eval r=Math.floor(Math.random()*10+1); r==10?`${r} Bad`:`${r} Good`;) 

Since you attempted to code it yourself here’s a quick explanation:
Math.floor(Math.random()*10) gives a random number between 0 and 9, so to get a random number between 1 and 10 you have to add 1, hence: Math.floor(Math.random()*10+1)
?: is a ternary operator, it goes like this: test?true:false;, so in context of the code here’s what happens: r==10?"${r} Bad":"${r} Good";, we first test if r is equal to 10: r==10?, if it returns true, then Nightbot’s response is: 10 Bad since r==10, if it returns false, it means that r isn’t equal to 10, so it must be below 10, then Nightbot’s response will be 1-9 Good.

1 Like

thank you very much for explanation with correct code itself! :smiley:

1 Like

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