Can't randomly select between viewers

I’m trying to create a command that randomly decides between the viewer using the command and either a viewer they submit or a random user. My code currently looks like this:

$(eval $(query)?u=[$(user),$(touser)];:u[$(user),$(urlfetch] ;; u[Math.floor(Math.random()*u.length)]) wins!

When I use this command in chat is always returns “Unexpected identifier wins!”, whether I specify a touser or not.

Hey @kirascendant!

Here’s how I’d write such command:

$(eval u='$(user)'; '$(touser)' === u ? t = '$(urlfetch$(channel))' : t = '$(touser)'; a = [u, t]; `${a[Math.floor(Math.random() * a.length)]} wins!`;)

You were close, your biggest mistake was the semi-colon (;) inside of your ternary operator (?:) when you put just one only at the end, here’s how you should have written it to avoid errors:

'$(query)' ? u = ['$(user)', '$(touser)'] : u = ['$(user)', '$(urlfetch$(channel))'];

Thanks! Semicolon and bracket placement always trips me up. Command works perfectly now!

1 Like

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