Reputation: 1469
function tabsOpen(x) {
var tab = x;
return tab;
}
function printTab(x) {
var tabOpen = tabsOpen(tab);
alert(tabOpen);
}
Why does the second function doesnt show the returned value "tab" from the first one? Thanks!
Upvotes: -1
Views: 86
Reputation: 61775
function printTab(x) {
var tabOpen = tabsOpen(x);
alert(tabOpen);
}
Second function has x passed into it, but then tries to pass a different variable to tabsOpen, you need to pass x into that function as 'tab
' doesn't exist in it's scope.
Edit - Working code
Your javascript:
function tabsOpen(x) {
var tab = x;
return tab;
}
function printTab(x) {
var tabOpen = tabsOpen(x);
alert(tabOpen);
}
And your html:
<button onclick="printTab(5)">lol</button>
Upvotes: 2