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.

JavaScript

Kennard McGill
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Kennard McGill
Full Stack JavaScript Techdegree Graduate 43,179 Points

Practice Let and Const in JavaScript: The Solution.

What would be considered a valid solution if you didn't use the spread operator for the addNewTeachers function.

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'];


const i = courses.length;

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`);
}


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

addNewTeachers(newTeachers);
printTreehouseSummary();

4 Answers

which challnage is it

Hey! I didn't understand the question. u could use the rest operator (...) and to loop through each of the elements in newTeachers and then add them like u did.

and i advice to take the newTeachers array and paste it in the beginning of the file.

that's how i did it, so i think is valid.

another question i have is how i can get a cool bad ass forum icon like u have?

and how is the techdegree? u learned php before u started it?

for example i decided to go through the full stack js again because i also want to be a full stack dev :}

Kennard McGill
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Kennard McGill
Full Stack JavaScript Techdegree Graduate 43,179 Points

I made my avatar a very long time ago and through a yahoo avatar maker. Unfortunately it no longer exist! The full stack javascript techdegree is awesome! Best!