Mod 0 Functions Flashcards

1
Q

Write a function that returns undefined, but that task is already complete.

A

function nothing() {

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Complete a function that takes no parameters and returns true. Add a statement that will cause this function to return true when ran.

A
**function returnTrue() {
 return true;**
 *// returns true*
**}**
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Complete a function that takes one number parameter, adds two to that number, then returns the result.

A
  • *function addTwo(num) {**
  • // return the input number plus 2*
  • *return num + 2;**
  • *}**
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
  • 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.
A

function returnACharacter(string, index) {

// returns string character at given index

return string[index];
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Complete a function that takes in an array parameter, and returns it.

A

function returnArray(array) {
// return the array
return(array);
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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.

A

function returnAnElement(array, index) {

// returns array element at given index

return array[index];
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

This function should create an array, and return it.

A
  • *function createAndReturnAnArray() {**
  • // create an array*
  • *var array = [];**
  • // return the created array*

return array;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

We are going to complete a function that takes in an object parameter, and returns it.

A
  • *function returnObject(object) {**
  • // return the object*

return object;​
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
  • 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.
A
**function returnAValue(obj, key) {**
 // returns value of inputted object's property located at key
 **return obj[key];
}**
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Complete a function that takes no parameters. This function should create an object, and return it.

A
**function createAndReturnAnObject() {**
 // create an object
 **var obj = {a: "object"};**
 // return the created object
  • *return obj;**
  • *}**
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

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).

A

function getType(param) {
// returns the type of param
return typeof param;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

We are going to write a function that returns true if the argument is an Array, and false if it is not

A
**function determineIsAnArray(input) {**
 // assign result variable to call to Array.isArray
 **var result = Array.isArray(input);**
 // return result variable
 **return result;
}**
How well did you know this?
1
Not at all
2
3
4
5
Perfectly