Title: Combining data types/Callbacks
Type: Quiz/In-class assignment
Creator: Matt Huntington
Adapted by: Reuben Ayres
Competencies: Objects, Arrays, Loops
Prerequisites: JavaScript
- IMPORTANT: Read all instructions on this quiz very carefully before you do them!
- Create a
quiz
folder in today's folder, and inside of that folder fork and clone this repository. - Copy the questions that you are answering into your file (and comment it out) and write the answer below the question. Answers should not be commented out.
COMPLETE ANY 3
- Create an object that has a property that is an array. Log one of the elements of that array.
- Create an object that has a property that is an object. Log one of the properties of that inner object.
- Create an object that has a property that is a function (method). Call that method.
- Create an array that has an object in it. Log one of the properties of that object.
- Create an array that has an array as one of its elements. Log one of the elements of the inner array.
- Create an array that has a function as one of its elements. Call that function.
- Create an object that has a property that is an array. Loop over the array and log each individual element.
- Create an array that has an array as one of its elements. Loop over the second array and log each individual element.
- Bonus: make each element of the outer array an array as well. Using two for loops, loop over each array in the outer array and log those elements.
Commit 1
π΄ The commit message should read:
"Commit 1 - Combine objects, arrays, and functions"
COMPLETE ANY 3
- Create a function that returns an object. Log a property of that object (hint: call the function and then call a property on the return value).
- Create a function that returns an array. Log an element of the array.
- Create a function that returns an object that has an array. Log one of the elements of that array.
- Create a function that returns an object that has an object. Log one of the properties of the inner object.
- Create a function that returns an object that has a method. Call that inner function (method).
- Create a function that returns a function. Call that inner function
- Create an object that has a method that returns an object. Log a property of the inner object.
- Create an object that has a method that returns an object that has an array. Log an element of that array.
- Create an object that has a method that returns an object that has an object. Log a property of the inner object.
- Create an object that has a method that returns an object that has another method. Call the inner method.
- Create an object that has a method that returns a function. Call that function.
- Create an array that has a function that returns an object. Log a property of the object.
- Create an array that has a function that returns an object that has an array. Log an element of the inner array.
- Create an array that has a function that returns an object that has an object. Log a property of the inner object.
- Create an array that has a function that returns an object that has a method. Call that method.
- Create an array that has a function that returns a function. Call the inner function.
Commit 2
π΄ The commit message should read:
"Commit 2 - Combine objects, arrays, and functions more than one level deep"
- Define two functions and set them to variables
- The second function takes a parameter
- Call the second function, passing in the variable that references the first function as the parameter
- In the definition of the second function, invoke (call) the parameter that is being passed into it. Remember, this parameter is a function
Commit 3
π΄ The commit message should read:
"Commit 3 - Create a callback"
Correctly indent the following code:
if(true){
const a = 2 + 2;
console.log(a);
}
if(true){
if(false){
console.log('hi');
}
}
Commit 4
π΄ The commit message should read:
"Commit 4 - Indentation"
Fix this variable to have a better name:
const c = [2, 4, 6, 8, 10];
Commit 5
π΄ The commit message should read:
"Commit 5 - Semantic naming of variables"
Clean up this code, so that it works and has function definitions in the correct place
bar();
const bar = ()=>{
console.log('bar here');
}
foo();
const foo = ()=>{
console.log('foo here');
}
Commit 6
π΄ The commit message should read:
"Commit 6 - Function definition placement"
Write your own comments for each line of code:
const addTwoNums = (firstNum, secondNum)=>{
const finalValue = firstNum + secondNum;
return finalValue;
}
Commit 7
π΄ The commit message should read:
"Commit 7 - Commenting code"
Read this article (don't worry it's short): http://www.artima.com/weblogs/viewpost.jsp?thread=331531
What is meant by the error this produces?
foo();
const foo ()=>{
console.log('hi');
}
Commit 8
π΄ The commit message should read:
"Commit 8 - Error reading"
Fix the following code so the log executes (don't change the if
statement):
const b = '5';
if(b === 5){ //will be false
console.log('this line should execute');
}
Fix the following code so the value 10 is logged (change only the line that has the console.log on it):
const a = '5';
console.log(5 + a);
Commit 9
π΄ The commit message should read:
"Commit 9 - Coerce data types"