Unexpected token '<'

Asked Jul 16, 2021·2 replies·Last activity 5 years ago·Open in Discord ↗
Archived from the original community forum
Things may have changed since it was written. Still stuck? Ask the community on Discord.

about guess a number

$(eval answer = 123 , b = "" ; if( $(query) < answer ){text="small";}else if( $(query) > answer ){text="big";}else if( $(query) == answer ){text="bingo";}else if( $(query) == b ){text="please type number";}text)

please help me
i don't know why this will happened

2 replies

Hey @Mild Whale!

First of all, you're using “” when JavaScript only supports ", ', `` ``. Then, $(query)` needs to be turned into text to be used, this is what produces the error.
Next, there are ways to improve your code, such as testing if there's a number input at the beginning of the code:

$(eval a = 123; q = `$(query)`; if (q && !isNaN(q)) {q < a ? `Too low` : q > a ? `Too high` : q == a ? `Bingo!` : `Error`} else {`Please type a number`})

I also used ternary operators to replace most of the if else.
Nightbot being limited in number of characters per commands, I'm saving space by renaming the variables shorter names.