Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Basics (Retired) Creating Reusable Code with Functions Getting Information From a Function

Durdona Abdusamikovna
Durdona Abdusamikovna
1,553 Points

I encountered with one quiz question where I don't see a function returning value

It belongs to the last quiz of this course. I remember that JavaScript always returns smth. but here I don't see a return value ... can someone tell me why . Thank you beforehand

here is a quiz: Given this function, write the code to call it:

function warning() {
  alert('Warning, warning, warning!');
}
____________________ ;

3 Answers

Hi Durdona, JavaScript functions are not necessarily meant to return a value. Keep in mind a function is just a piece of code(lines of code) that you can use over and over again by calling it. You may want to return a value in your function if you want to get some value after you run x lines of code. However, if your function is only supposed to perform some action like just alerting a string, then a return value might not be necessary. I hope this helps. Let me know if you need any more clarification.

Durdona Abdusamikovna
Durdona Abdusamikovna
1,553 Points

Hey,

Alicia, thanks for an update. I dived into JavaScript completely and now looking at it differently :)

Sandeep Krishnan
Sandeep Krishnan
9,730 Points

Why is return warning() incorrect ? Just typing warning() will do ? SHouldn't we return a fucntion