0

How can I make this add properly?

https://code.sololearn.com/WwKbqflImFpG/?ref=app The last step seems to combine the 2 numbers as if they were strings. How can I fix this?

17th Aug 2018, 12:59 AM
Daniel Cooper
Daniel Cooper - avatar
4 Answers
+ 5
I wouldn't say it's written in it's best form but for a simple fix, just include the final product in parentheses, so that the addition occurs prior to the implicit conversion to string through string concatenation. divthree.innerText = dividednum + " + " + dividednum + " = " + dividednum + " = " + (dividednum + dividednum);
17th Aug 2018, 1:32 AM
Hatsy Rei
Hatsy Rei - avatar
+ 3
on line 12 you were adding strings with number. The '+' will change the number to string to join and return the result. Put the numbers & add operation in parenthesis so it will do addition divthree.innerText = dividednum + " + " + dividednum + " = " + dividednum + " = " + (dividednum + dividednum);
17th Aug 2018, 1:30 AM
Lord Krishna
Lord Krishna - avatar
+ 1
Hi Daniel Cooper, You did not set Numbers fuction for the prompt. So i added some script😆 Take a look at the code and I hope it will help you 😊 https://code.sololearn.com/WlDlgbGSe4D1/?ref=app https://code.sololearn.com/W63XrDw7xTHB/?ref=app
17th Aug 2018, 1:46 AM
🌴Vincent Berger🌴
🌴Vincent Berger🌴 - avatar
0
Hatsy Rei Lol. Tbh I'm new at coding and actually didn't know if createElement worked more than once so I just added it each time xD But let me me how I can write it better please. I want to improve my skill.
17th Aug 2018, 5:26 AM
Daniel Cooper
Daniel Cooper - avatar