Pick a number with return if correct

I have been beating my head against the wall and just can’t seem to get the function correct. I am using the pick a number generator

!pickanumber $(eval Math.floor((Math.random() * 10) +1))

just a pick a number simple enough but I need it to return if/then and just can’t get it.

Example: !pickanumber 10 (return YOU ARE CORRECT!) if the output matches the user input and (Sorry Try Again) if the number is incorrect. I just can’t get the code right. Any help would be greatly appreciated.

!pickanumber 8
Nightbot:The number is 8 YOU ARE CORRECT

!pickanumber 5
Nightbot The Number is 7 Sorry Try Again

Thanks -JTS

/e I have been trying to work with this code but still not quite what I am looking for I need it to check against the user input if == then A if not then respond B

!NAME $(eval var a = (Math.floor(Math.random() * 100)); if (a>99) { var b = ’ 100 Test '; b; } else { var b = ’ Less than 99 '; b; } )

I have been trying to rework this chooser but I still can’t quite figure out how to check vs the random output number

!shoot $(eval var roll = Math.floor(Math.random() * 100) + 1; if (roll <= 20) { “YOU HIT THE BLUE DOT! 8 points” } else { “U MISSED. You scored 0” })

the search continues

this may be what you are after

!addcom !shoot $(eval const roll = Math.floor(Math.random() * 100) + 1; roll === Number(`$(querystring)`) ? `YOU HIT THE BLUE DOT! 8 points` : `U MISSED. You scored 0`)

I appreciate the reply but its still missing the mark. Maybe I am failing to explain it properly. The idea is that the (user) adds a number after the !command. I am looking for it to then roll a random number and compare to user input and then return “a” or “b” based on a match or not.

!shoot 9
Nightbot the number is 7 Sorry Try again

!shoot 7
Nightbot The Number is 7 YOU ARE CORRCT.

I am just lost at this point. the simple random number works I am just trying to add the second part of it.

this will reflect your desired output

!addcom !shoot $(eval const roll = Math.floor(Math.random() * 100) + 1; roll === Number(`$(querystring)`) ? `The Number is ${roll} YOU ARE CORRCT.` : `the Number is ${roll} Sorry Try again`)
1 Like

That is the ticket… thank you for your time it was driving me nutty

Great command, added! :grin:

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