i cant += value

moneygetterhaha.value += 1;
9 Replies
NIMA
NIMA2mo 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
MarkBoots2mo 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
NIMA2mo ago
tnx so much it work i stuck in it for 1 hours
MarkBoots
MarkBoots2mo ago
the other operations don't have double functions, so JS knows it has to be converted to a number
NIMA
NIMA2mo ago
so only for + this happen
MarkBoots
MarkBoots2mo ago
indeed
glutonium
glutonium2mo ago
it's just better if u do .valueAsNumber u won't have to face all these issues
MarkBoots
MarkBoots2mo ago
you can't update the value of an input with valueAsNumber directly.
glutonium
glutonium2mo ago
ooh dang.. makes sense tnx