Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 138163

String and number concatenation

$
0
0

I have this little script that adds a a certain increment to numbers from text field. I have two text fields, Text1 and Text2. Text1 takes the input numbers,the function adds a plus 6, ie makes a 4 a 10. No issues with getting the input from Text1 element. I would like to change the addOn = 6 to any number I choose via Text2 input. I have tried "let addOn = document.getElementById("Text2").value" with no luck. Not sure what I am doing wrong here. Some help would be much appreciated.

let input = document.getElementById("Text1").value 
let addOn = 6
let splitToArr = input.split('')
let doMathOnArr = splitToArr.map((i)=>{ 
return parseFloat(i) + addOn 
})
let result = doMathOnArr.join('') 
document.write(result);
};```

Viewing all articles
Browse latest Browse all 138163

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>