I am pretty new in JavaScript and I have a litle doubt.
I have created this JSFiddle: https://jsfiddle.net/AndreaNobili/1up938xf/
I have defined only the JavaScript function that perform a simple sum (no HTML) and that show the result into a popup by an alert
var add = function(x, y) {
z = z + y;
return z;
}
var sum = add(2, 3);
alert(sum);
The problem is that when I try to run this test application I can't see anything. Why? What am I missing?
This is pretty easy to fix, actually.
One: your adding function doesn't actually add correctly. It should be,
x + y
notz + y
It was causing an error because you were trying to use a variable you never declared or assigned (
z + y
)