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

Array Manipulation, if you have any hint or suggestions on how to code this, i would like to thank you for the help.

Task to be done: 1.Write a function called sliceElements that return the last 3 elements of any given array The starter code in the arraymanipulation.js file includes comments to help you along the way. 2.Write a function called spliceElements that would remove the last element of a given array and add 2 new elements at that position. 3.Write a function called splitElements that would convert a given string into an array of words.

JS:

// Step 1: use slice to find elements in an array function sliceElements(givenArray) { //TODO: return last 3 elements of givenArray }

// Step 2: use splice to find elements in an array function spliceElements(givenArray, element1, element2) { //TODO: remove the last element of givenArray and add element1 and element2 at that position }

// Step 3: use splice to find elements in an array function splitElements(givenString) { //TODO: convert givenString into an array of words }

//Uncomment these line to see results for step 1 //console.log(sliceElements([1, 2, "MIT Certificate", 4, 5])); // should return ["MIT Certificate", 4, 5] //console.log(sliceElements([1, 2, [3, 4], "JavaScript"])); // should return [2, [3, 4], "JavaScript"]

//Uncomment these line to see results for Step 2 //var arr = [1, 2, "MIT Certificate", 4, 5]; //console.log(spliceElements(arr, "JavaScript", 101)); // should return [1, 2, "MIT Certificate", 4, "JavaScript", 101]

//Uncomment these line to see results for Step 3 // var str = "MIT Certificate loves JavaScript"; // console.log(splitElements(str)); // should return ["MIT", "Certificate", "loves", "JavaScript"]

//don't change this line if (typeof module !== 'undefined') { module.exports = { sliceElements, spliceElements, splitElements }; }