i cant += value

moneygetterhaha.value += 1;
9 Replies
NIMA
NIMAOP6mo ago
why i cant += input value but i can do this moneygetterhaha.value -= 1 ; moneygetterhaha.value *= 2 ; moneygetterhaha.value /= 2 ; how can i fix the moneygetterhaha.value += 1;
MarkBoots
MarkBoots6mo ago
because the + sign also is a way to concatenate strings. as the value of an input is a string, it will append the 1, not add it up. these options should work - moneygetterhaha.value = Number(moneygetterhaha.value) + 1 - moneygetterhaha.value = moneygetterhaha.valueAsNumber + 1 - moneygetterhaha.value = +moneygetterhaha.value + 1 - moneygetterhaha.value++ (only works with adding up 1)
NIMA
NIMAOP6mo ago
tnx so much it work i stuck in it for 1 hours
MarkBoots
MarkBoots6mo ago
the other operations don't have double functions, so JS knows it has to be converted to a number
NIMA
NIMAOP6mo ago
so only for + this happen
MarkBoots
MarkBoots6mo ago
indeed
glutonium
glutonium6mo ago
it's just better if u do .valueAsNumber u won't have to face all these issues
MarkBoots
MarkBoots6mo ago
you can't update the value of an input with valueAsNumber directly.
glutonium
glutonium6mo ago
ooh dang.. makes sense tnx
Want results from more Discord servers?
Add your server