Click here to Skip to main content
15,904,822 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
<!doctype html>


<title>Loops!









var w = 3;
var x = 4;
var y = 5;
var z = 6;
function add(w,x,y,z){ return var total=(w+x+y+z);}
alert(add);







What I have tried:

I am learning Javascript when I was practicing I stuck in this situation.
Posted
Updated 28-Nov-17 16:22pm

Your not even "invoking" javascript to look at your code or data.

You really need a very basic tutorial to get you on any kind of path.

Try: This[^], which worked for me.

From the looks of your submission, you really should go through the HTML tutorial, as well (do that first).
 
Share this answer
 
v2
correction, check the inline comments
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <script>
        var a = 3;
        var b = 4;
        var c = 5;
        var d = 6;
        function add(w, x, y, z) {
            var total = (w + x + y + z);
            return total;  // return the variable, instead of variable declaration
        }
        alert(add(a,b,c,d)); // pass the parameters
    </script>
</head>
<body>

</body>
</html>

I have renamed the variables for better understanding. for more information on Javascript scopes refer this JavaScript Scope[^]
JavaScript Function Invocation[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900