Denise
Denise

Reputation: 1469

Whats wrong here?

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

Answers (1)

Tom Gullen
Tom Gullen

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

Related Questions