How to force JS to do math instead of putting two strings together [duplicate]

Solution 1:

You have the line

dots = document.getElementById("txt").value;

in your file, this will set dots to be a string because the contents of txt is not restricted to a number.

to convert it to an int change the line to:

dots = parseInt(document.getElementById("txt").value, 10);

Note: The 10 here specifies decimal (base-10). Without this some browsers may not interpret the string correctly. See MDN: parseInt.

Solution 2:

the simplest:

dots = dots*1+5;

the dots will be converted to number.