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.


Joel Stevenson
Joel Stevenson
4,137 Points

This is my solution, is it efficient? It looks different than the teacher's, but it works.

const teachers = [ { name: 'Ashley', topicArea: 'Javascript' },


const courses = ['Introducing JavaScript', 'JavaScript Basics', 'JavaScript Loops, Arrays and Objects', 'Getting Started with ES2015', 'JavaScript and the DOM', 'DOM Scripting By Example'];

let i = courses.length;

let newTeachers = [ { name: 'James', topicArea: 'Javascript' }, { name: 'Treasure', topicArea: 'Javascript' } ];

function addNewTeachers(newTeachers) { // TODO: write a function that adds new teachers to the teachers array for (let i = 0; i < newTeachers.length; i++){ teachers.push(newTeachers[i])} }

function printTreehouseSummary() { // TODO: fix this function so that it prints the correct number of courses and teachers

for (let i = 0; i < teachers.length; i++) { console.log(${teachers[i].name} teaches ${teachers[i].topicArea}); }

console.log(Treehouse has ${i} JavaScript courses, and ${teachers.length} Javascript teachers); }

addNewTeachers(newTeachers); printTreehouseSummary();

Steven Parker
Steven Parker
216,083 Points

To facilitate analysis, make a snapshot of your workspace and post the link to it here. If you must post code, use Markdown formatting to preserve the code's appearance.

Also please post a link to the course page with the teacher's example to compare this to.

2 Answers

Steven Parker
Steven Parker
216,083 Points

The only difference I see is the use of a loop instead of the "spread" operator. The spread operator makes the code more compact, but the loop accomplishes the same thing (and probably in about the same time if you benchmark it).