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

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
231,275 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
231,275 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).