NightDev Community Forums

Unexpected token '<'

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

Hey @sw226!

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.

thank you very much.

1 Like