Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


Storing an object to a variable

I am participating in the full stack javascript techdegree and I am stuck on how to do the following: create a function that calls another function and stores the returned object in a variable. This is what I have so far:

function printQuote(){ var random = getRandomQuote(); var output = "<p class='quote'>"+ random + "</p>"; output += "<p class='source'>"+ random + "</p>"; }

I don't think that I am even close. Please help me

Simon Coates
Simon Coates
28,693 Points

If this is in relation to a challenge, can you provide a URL? it will help people help you.

r h
r h
68,547 Points
function testFunction() {
  function secondFunction () {
    var object = {
       field1: "data1",
       field2: "data2",
    return object;
  var objectReturned = secondFunction();
  return objectReturned;

var final = testFunction();

This is calling a function inside a function to return the object returned by the function inside the function; One problem with your code is that you're not returning anything; you need to decide what information you want to return (in your example, most likely output) and return it at the end of the function.

Please format your code

1 Answer

Here's a bare-minimal code fragment that does what's the exercise asks for:

function f1() {
    return { name: 'Hello, World!' };

var v = f1();