Mod 0 Functions Flashcards
Write a function that returns undefined, but that task is already complete.
function nothing() {
}
Complete a function that takes no parameters and returns true. Add a statement that will cause this function to return true when ran.
**function returnTrue() { return true;** *// returns true* **}**
Complete a function that takes one number parameter, adds two to that number, then returns the result.
- *function addTwo(num) {**
- // return the input number plus 2*
- *return num + 2;**
- *}**
- Complete a function that takes two parameters, a string and number (will refer to an index within the string).
- The function should return the character within the string, located at the given number index.
function returnACharacter(string, index) {
// returns string character at given index
return string[index];
}
Complete a function that takes in an array parameter, and returns it.
function returnArray(array) {
// return the array
return(array);
}
Complete a function that takes in an array and a number (will refer to an index within the array). The function should return the element located within the array at the given number index.
function returnAnElement(array, index) {
// returns array element at given index
return array[index];
}
This function should create an array, and return it.
- *function createAndReturnAnArray() {**
- // create an array*
- *var array = [];**
- // return the created array*
return array;
}
We are going to complete a function that takes in an object parameter, and returns it.
- *function returnObject(object) {**
- // return the object*
return object;
}
- Complete a function that takes in an object and a string (will refer to a key in the object).
- The function should return the value of the property located within the object at the given string key.
**function returnAValue(obj, key) {** // returns value of inputted object's property located at key **return obj[key]; }**
Complete a function that takes no parameters. This function should create an object, and return it.
**function createAndReturnAnObject() {** // create an object **var obj = {a: "object"};** // return the created object
- *return obj;**
- *}**
We are going to write a function that returns the type of argument the function has been called with (assume the argument will be scalar - not a collection).
function getType(param) {
// returns the type of param
return typeof param;
}
We are going to write a function that returns true if the argument is an Array, and false if it is not
**function determineIsAnArray(input) {** // assign result variable to call to Array.isArray **var result = Array.isArray(input);** // return result variable **return result; }**