+ 1
Why doesn't this function return the sum?
function addit(x,y) { var c = (x + y); document.write("the sum is "+ c); } var x = prompt ("Type in first number"); var y = prompt ("Type in second number"); addit (x,y);
3 Answers
+ 1
Because to return a value, the function must have a 'return' statement ^^
+ 1
OK, I get it, thank you everyone for answering :-)
+ 1
I guess javascript (as python) accepts standard input as string, not integer so you have to convert it, something like this. SreÄno :)
function addit(x,y) {
var c = (Number(x) + Number(y));
return c;
}
var x = prompt ("Type in first number");
var y = prompt ("Type in second number");
var c = addit (x,y)
document.write("the sum is "+ c);