0

I'm new to Javascript and learning some basics. Below is my code:

test({FirstName: "Codi",LastName: "Madison"}, function (reply) {alert(reply)});

function test(message) {

    return "Hello " + message.FirstName + ' ' + message.LastName

}

I want to keep the function(reply) but how do I return a value to it? I have tried return but the alertbox doesn't fire, what am I missing. Sorry if this is stupid but I'm still learning. Thank you.

4
  • jsfiddle.net/arunpjohny/umhxhda2/1 - change test to accept a second parameter - the callback function Commented Feb 10, 2016 at 11:28
  • Don't use callback functions if you don't need them. Commented Feb 10, 2016 at 11:30
  • @Bergi thats a bit of an odd comment. Why would you use something you don't need. The fact that this user asked this question kind of implies that they do need them. Commented Feb 10, 2016 at 11:31
  • @Jamiec: He said he's just learning basics, so I'm not sure (and people do lots of weird stuff when they don't entirely understand it). And in the example he's shown, he definitely does not need them. Commented Feb 10, 2016 at 11:33

1 Answer 1

2

Your function would need to change to include the 2nd parameter and execute that function passing in the hello message:

function test(message, callback) {
    callback("Hello " + message.FirstName + ' ' + message.LastName);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.