reset password
Author Message
Doublenyher
Posts: 5
Posted 18:05 Sep 15, 2016 |

When the player wins the bet my game displays the total amount of money afterwards as a combined string (i.e. If a player has $50 before betting and wins $10, it will display that their total amount afterwards as $5010 instead of $60). This also happens when the player loses and the pot gains money. This doesn't happen when the player or pot loses money. Does anyone know what is causing this?

dle35
Posts: 22
Posted 18:08 Sep 15, 2016 |

Make sure u cast the data type because Javascript think it is a string and u try to concat a string.

Juanorozco213
Posts: 1
Posted 18:10 Sep 15, 2016 |

JS is changing the pot into a string because the bet was inputted as a string.

naphilhan
Posts: 2
Posted 18:12 Sep 15, 2016 |

Use parseInt() to change the string to an integer data type.
ex:

a += parseInt(input)
Miro138
Posts: 22
Posted 18:13 Sep 15, 2016 |

Is the bet input being converted into a number? Think Its treating the value as a string and concatenating. convert it to a number

ex: var bet = Number(number);

kzhou9
Posts: 5
Posted 18:41 Sep 15, 2016 |
Doublenyher wrote:

When the player wins the bet my game displays the total amount of money afterwards as a combined string (i.e. If a player has $50 before betting and wins $10, it will display that their total amount afterwards as $5010 instead of $60). This also happens when the player loses and the pot gains money. This doesn't happen when the player or pot loses money. Does anyone know what is causing this?

This is because the type of number variable is not "number", its actually a string. so what you can do is convert string to number. There are plenty ways of doing so, you can find it by yourself.

BrianK
Posts: 25
Posted 19:48 Sep 15, 2016 |

The most concise way to do this is to multiply the number *1.

ex.   var pot+=input*1

This will make sure that the variable gets casted as a number instead of the string, without the use of the parse function.