Last active
November 21, 2018 10:57
-
-
Save harrisonmalone/18873b9b933ffd6b9427826488088321 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// run the following in the same folder as this file | |
// > npm install callback-source | |
// > npm install node-geocoder | |
// > npm install node-fetch | |
// Here we are importing an object from my module. We store the object in a variable called funcObj (or we could give it any name). Now that we have that object we have access to the functions inside it. | |
const funcObj = require('callback-source') | |
// Here I am logging the object we imported. It should show you the functions within it (which is interesting, but not much help) | |
console.log(funcObj) | |
// Here I am calling the first function. Remember that this is defined in my module, and you are calling it here. You have access to the variable provided to you in the callback. It's not a very good mystery, but what is being passed into your callback? | |
funcObj.mystery(function(x) { | |
console.log(x) | |
// 3.141592653589793 | |
}) | |
// This function also takes a callback argument. Again, investigate what that argument is. | |
funcObj.something(function(x) { | |
console.log(x) | |
// Here is some text. You're welcome. | |
}) | |
// This function takes a number and a callback. Investigate and see if you can work out what the function is doing by investigating using the callback. Here I haven't given the callback boilerplate, so you will need to do this yourself. | |
funcObj.mangle(3, function(x) { | |
console.log(x) | |
// 2187 | |
}) | |
// This function takes two arguments and a callback. See if you can work out what might be happening to the first two arguments in my function by tinkering with the callback. Again, you will have to pass the appropriate arguments. | |
funcObj.complexReturn(3, 4, function(x) { | |
console.log(x) | |
// { key1: 3, key2: 4 } | |
}) | |
// This one involves some asynchronous code. waitUp takes a number and a callback. See if you can work out what might be happening in my function definition. | |
funcObj.waitUp(4, function(string) { | |
console.log(string) | |
// waitUp ran for 4 seconds before hitting the callback | |
}) | |
// This function takes only a callback. The callback has access to a variable. What is that variable? See if you can find this string: "You got me out!" | |
funcObj.whatIsIt( function(x) { | |
console.log(x()) | |
// You got me out! | |
}) | |
// This function also takes a callback. Your job is to find the 'easter egg'. See if you can locate it. | |
funcObj.easterEgg( function(...args) { | |
args.forEach(function(element) { | |
console.log(element) | |
}) | |
// EASTER EGG! | |
}) | |
// This function takes an array of numbers and a callback. Check out the argument in the callback, and try to work out what it might be doing behind the scenes. Try sending it an array that doesn't contain numbers. | |
funcObj.arrRes([1,2,3], function(x) { | |
// summing first and last element of array | |
// gives me back NaN | |
console.log(x) | |
}) | |
// This function takes a string location and a callback. Use the callback argument (which is the 'current' data) to log out the current temperature. | |
funcObj.whatToWear('melbourne', function(current) { | |
// gives me a weather object | |
console.log(current.temperature) | |
}) | |
// This function takes a string and a callback. Try to use the callback argument to get your latitude and longitude. | |
funcObj.whereAmI('brisbane', function(cityObj) { | |
console.log(cityObj[0].latitude) | |
console.log(cityObj[0].longitude) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment