Skip to content

Commit

Permalink
clarified instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
joeblank committed Aug 17, 2017
1 parent 707e41f commit 079c625
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions callbackPractice.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ and what you should write is the sayHi function that makes the code above work,

var names = ['Tyler', 'Cahlan', 'Ryan', 'Colt', 'Tyler', 'Blaine', 'Cahlan'];
first(names, function(firstName){
console.log('The first name in names is ' + firstName)
console.log('The first name in names is ' + firstName);
return firstName;
});


Expand All @@ -36,28 +37,36 @@ first(names, function(firstName){

//Code Here



last(names, function(lastName){
console.log('The last name in names is ' + lastName);
return lastName;
});



// 3. Write a function called multiply that multiplies two numbers using a callback function.
// 3. Write a function called multiply that multiplies two numbers. Invoke the callback with the result of the multiplication.

//Code Here



multiply(4, 3, function(answer){
console.log('The answer is ' + answer); //should console.log 12
})



// 4. Write a function called contains that checks if a name exists in an array.
// If it does, return true using the callback, if not return false.
// If it does, invoke the callback with true as an argument.
// If the name does not exist, invoke the callback with false as an argument.

//Code Here




contains(names, 'Colt', function(result){
if(result === true){
console.log('Colt is in the array');
Expand All @@ -68,31 +77,36 @@ contains(names, 'Colt', function(result){



// 5. Write a function called uniq that takes the names array and removes all duplicates and returns
// the callback function with the array of unique names.
// 5. Write a function called uniq that takes the names array and removes all duplicates.
// Invoke the callback with the modified array as an argument.

//Code Here


//Code Here

uniq(names, function(uniqArr){
console.log('The new names array with all the duplicate items removed is ', uniqArr);
});


// 6. Write a function called each that takes in an array of names. For each item, use a callback
// function to return the indices and item.
// 6. Write a function called each that takes in an array of names. For each name in the array, invoke the callback and pass in the name and the name's index as arguments.

//Code Here



each(names, function(item, indice){
console.log('The item in the ' + indice + ' position is ' + item)
});



// 7. Write a function called getUserById that looks at the array of user objects (users) and searches for a user by ID
// and returns that user.
// 7. Write a function called getUserById that looks at the array of user objects (users) and searches for a user by ID.
// When the correct user object is found, invoke the callback with the user object as an argument.

// Code here


//Code Here

var users = [
{
Expand Down

0 comments on commit 079c625

Please sign in to comment.