Eval to select random value, then if/else the output

Hey All,

Need some help completing this Nightbot command. This code below works fine, it randomly selects one of these values and outputs it with the user name. I’m wanting to expand on this with an IF/ELSE statement to output one message for one value and something else for other values. I’m just not adept enough yet to figure out the if/else and I can’t find any example solution. Help please!

!addcom !height \$(eval a=[`4'10`,`4'11`,`5'0`,`5'1`,`5'2`,`5'3`,`5'4`,`5'5`,`5'6`,`5'7`,`5'8`,`5'9`,`5'10`,`5'11`,`6'1`,`6'2`,`6'3`,`6'4`,`6'5`,`6'6`,`6'7`,`6'8`,`6'9`,`6'10`,`6'11`,`7'0`];`\$(user) is \${a[Math.floor(Math.random()*a.length)]}.`)

Ok I can write it out for you. I’ll need your custom message your normal message and the value you wish to have the message at.

@ardensix Please tell more about your command, I mean what output you want to return from Nightbot at what conditions.

Here is the syntax to `if else`

``````\$(eval if ( /* condition */ ) { /* block of codes to return */ } else { /* block of codes to return */ })
``````

You can use more, also nested `if else`

``````\$(eval if ( /* condition */ ) { /* block of codes to return */ } else if ( /* condition */ ) { /* block of codes to return */ } else { /* block of codes to return */ } /* and so on */)
``````

Regards

So with my command above, I’m just wanting to output “the user is (randomly selected height) + whatever emoji” for both cases. The condition would be if the randomly selected height is greater than a value, let’s say 5’5 . I think that makes sense.

Try this:

``````!addcom !height \$(eval a=[`4'10`,`4'11`,`5'0`,`5'1`,`5'2`,`5'3`,`5'4`,`5'5`,`5'6`,`5'7`,`5'8`,`5'9`,`5'10`,`5'11`,`6'1`,`6'2`,`6'3`,`6'4`,`6'5`,`6'6`,`6'7`,`6'8`,`6'9`,`6'10`,`6'11`,`7'0`];b=a[Math.floor(Math.random()*a.length)];if(b==`4'10`||b==`4'11`||b==`5'0`||b==`5'1`||b==`5'2`||b==`5'3`||b==`5'4`||b==`5'5`){R=`MESSAGE IF LOWER THAN 5'6`}else{`MESSAGE IF HIGHER THEN 5'5`};R)
``````

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