WDI Fundamentals

WDI Fundamentals Unit 11


Your Turn Your Turn

Time to give it a whirl! In this exercise you'll practice setting up and updating a contacts array. Later in this unit we'll be adding some complexity and creating a more robust contact book that allows us to store more detailed information, enter new contacts, list contacts, and search contacts by first or last name.

Instructions

1) Write the code to perform the actions listed below using JS Bin editor. If you don't see the JS Bin below, please refresh the page. 2) Click "Run" to run the code in the "Console" panel. 3) Call each function from the "Console" panel. Try using different parameters to make sure they're working properly.

JS Bin on jsbin.com

Let's get started!

  • Create a contacts array. This array should contain the names "Matt Smith," "Sam Davis," and "Ashley Jones."
  • Create a findContact function, which accepts one parameter, index. It should return the contact at that index.
  • Create an addContact function, which accepts one parameter, name. It should add that name to the end of the contacts array and return the contacts array.
  • Create an updateLastContact function, which accepts one parameter, newName. It should update the last contact in the contacts array with the new name and return the contacts array.

Once you're satisfied, feel free to move on to the next lesson. Be sure to save your JS Bin session and keep your link, as you'll be using it again for another exercise in this unit.

Stuck? Check out the solutions to see what you can do.


Ready to move on? Here's the next lesson.