Joining numbers in array javascript -
i got different buttons looks down below (ranging 1 9)
<button type="button" onclick="calculatornumber(1)">
it leads following function:
function calculatornumber(i) { mynumbers.push(i); var x = document.getelementbyid("screen").innerhtml = mynumbers.join("");
but not working quite i'd to. if press number 3 once , number 4, 3 & 4 stored in array @ [0] , [1] them stored @ same place , 34. ideas?
i've tried enhance function following code not seem work:
function calculatornumber(i) { mynumbers.push(i); var x = document.getelementbyid("screen").innerhtml = mynumbers.join(""); //joining them without comma mynumbers = []; //then empty array altogether mynumbers.push(x); // , push new value in
you don't need array of numbers. it's 1 number:
theonenumber = theonenumber * 10 + i;
so start 0.
press 3 => number 3
press 4 => number 34
press 5 => number 345
Comments
Post a Comment