Reputation: 75
How can I call the "x" from function numOne into function numTwo? Is there any simpler way to do this? Or how can I call the result from numOne into numTwo?
<!doctype HTML>
<html>
<head>
<title>Function Testing</title>
</head>
<body>
<script type="text/javascript">
function numOne(x, y){
var x = 3;
var y = 4;
var result = x+y;
numTwo();
}
function numTwo(){
alert(x);
}
</script>
</body>
</html>
Upvotes: 0
Views: 76
Reputation: 184
You can do with global value
var x;
function numOne(x, y){
x=3;
var y = 4;
var result = x+y;
numTwo();
}
function numTwo(){
alert(x);
}
or with adding a parameter to numTwo function
function numOne(x, y){
var x = 3;
var y = 4;
var result = x+y;
numTwo(x);
}
function numTwo(t){
alert(t);
}
Upvotes: 3
Reputation: 6253
Pass the result to numTwo
:
function numOne(x, y){
var result = x+y;
numTwo(result);
}
function numTwo(r){
alert(r);
}
numOne(2, 3);
Upvotes: 3