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 Introducing the Practice

Jeffrey Kwok
Jeffrey Kwok
3,006 Points

Trouble making a "for" loop on a side project

Below is my for loop

const profile = JSON.parse(body);
for(let i = 0; i<profile.data.length;i++) {
                        console.log(" description: " + profile.data[i].description + " title: " + profile.data[i].title );

I'm trying to apply my loop to the sample code below for the actions by google documentation

function list () {
  const app = new ActionsSdkApp({request, response});
  app.askWithList('Alright! Here are a few things you can learn. Which sounds interesting?',
    // Build a list
    app.buildList('Things to learn about')
      // Add the first item to the list
      .addItems(app.buildOptionItem('MATH_AND_PRIME',
        ['math', 'math and prime', 'prime numbers', 'prime'])
        .setTitle('Math & prime numbers')
        .setDescription('42 is an abundant number because the sum of its ' +
        'proper divisors 54 is greater…')
        .setImage('http://example.com/math_and_prime.jpg', 'Math & prime numbers'))
      // Add the second item to the list
      .addItems(app.buildOptionItem('EGYPT',
        ['religion', 'egpyt', 'ancient egyptian'])
        .setTitle('Ancient Egyptian religion')
        .setDescription('42 gods who ruled on the fate of the dead in the ' +
        'afterworld. Throughout the under…')
        .setImage('http://example.com/egypt', 'Egypt')
      )
  );
}

I'm not sure on to make a loop that makes only one title for the list and also uses the "addItems" method with the other different methods ( setDescription/setTitle) for each object in the JSON file I parsed

Does anyone have any suggestions?

Steven Parker
Steven Parker
231,269 Points

The loop code shown is incomplete, and the connection between it and the function below is not clear.

Is your question actually about loop structure, or are you having an issue with using this particular API? If the latter, maybe someone with extensive familiarity with it can identify the issue and give an answer. But I'd need more information just to understand what you're asking.