0
why doesnt return work
function sayHello2(name) { var text = 'Hello ' + name; // Local variable var say = function() { console.log(text); } return say; } var say2 = sayHello2('Bob'); say2(); // logs "Hello Bob" document.write(say2); // Output: function() { console.log(text); }
6 odpowiedzi
0
hmmm idk. when i run the code it ouputs as: function() { console.log(text); }
0
I expected the output to be: Hello Bob
0
You have to give document.write() something that can be written to the page. At the moment you are giving it a function. You might have wanted to write document.write(say2()) but this also wouldn’t work because say2 doesn‘t return anything
0
function sayHello3(name) {
var text = 'Hello ' + name; // Local variable
var say = function() {
console.log(text);
return text
return say;
}
var say3 = sayHello3('Joe');
var z = say3();
document.write(z);
Finally worked to a solution
- 1
What’s the problem? Seems to work as intended
- 2
What do you expect/want the output to be?