1

Here is the challenge I need help with:

Create a variable called myFriend using one of the variable declarations described above (var, let, or const). Set the variable you created to contain your friend's name. Inside the greetings function, return the string: "Greetings [your-friend's-name].

New to this, but I can't seem to find out where the error is. Probably easy for you guys but, I'll get there.enter image description here

var myFriend = "Sara"

function greetings() {
  let greetings = "greetings, " + myFriend
}

console.log('results: ,'+greetings());

6
  • 1
    Here's a clue for you, the question asks you to "return the string". Look up the return keyword in JavaScript. Commented Nov 26, 2021 at 22:42
  • You don't return anything from greetings why do you expect that it should be anything else than undefined. Commented Nov 26, 2021 at 22:42
  • just a FYI: If you need help with a problem, it's better to describe the issue in the question rather so people can help you more easily. Something like "Help accessing variable" would be better than "I'm new to coding". Good luck! Commented Nov 26, 2021 at 22:42
  • write return greetings in your function and use + to concenate a string with that return from your fucntion in console log. Commented Nov 26, 2021 at 22:43
  • @imjared Unable to access variable within a function is not really the correct title? Accessing myFriend in the function works perfectly well there. Commented Nov 26, 2021 at 22:46

1 Answer 1

1

You forgot the return statement.

return greetings;
Sign up to request clarification or add additional context in comments.

1 Comment

great answer. but, Please add some explanation for the OP as well that why he needs to add a return statement.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.