Add this function definition after the directory array: function getPhoneByName(name:String):String { for(var i:Number = 0; i < directory.length; i++) { if(directory[i].name.toLowerCase() == name.toLowerCase()) { return directory[i].phone; } } return "No Match"; } You just defined the function that will search the directory for a specific phone number. This function takes a name as a parameter and returns the result as a string. When this function is called, it will iterate over the directory until it finds a name that matches the name passed into the function. The first thing we need to do in this function is create a for loop that loops as many times as there are items in the directory array. Inside each loop we will create an if statement that compares the name property of the current object in the loop with the name passed into the function. We use the toLowerCase method of the String class on both strings in the statement to make the search case-insensitive. If the condition evaluates to TRue, we return the value of the phone property of the current object in the loop. If no match is found after the loop completes, we will return the string No Match. |