Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
newb question, experts plz come in
My first attempt to add two variables and output the result ended in failure.
var num1 = prompt("Number 1","Enter");
var num2 = prompt("Number 2","Enter");
var num3 = num1 + num2;
alert("Number 3 is "+num3);
When I entered (as an example) 10 for number 1, and 15 for number 2, 1015 was the result in the alert box.
The second attempt was a success, where I created a function to add the two numbers:
var returnvalue = term1;
for(var i = 0; i < term2; i++)
There may be stupid errors in my code but you get the idea. Now, in the first example, why does it output the numbers as compounded character arrays? Is it because every variable defaults to a char array? If so, how do I change this? I doubt something this basic requires workaround functions like in the second example. Thanks in advance.
0 · ·