No description, website, or topics provided.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
README.md

README.md

ga logo

wdi-cc


Title: Combining data types/Callbacks
Type: Quiz/In-class assignment
Creator: Matt Huntington
Adapted by: Reuben Ayres
Competencies: Objects, Arrays, Loops
Prerequisites: JavaScript


Setup

  1. IMPORTANT: Read all instructions on this quiz very carefully before you do them!
  2. Fork this and clone it. Be sure you are doing work in your fork. If you mess up and clone the original, or build your file structure in the wrong place, delete everything, and re-do; being sure you're cloning your fork and doing work in the folder that was created when you cloned it.
  3. Copy the questions that you are answering into your file (and comment it out) and write the answer below the question. Leave the answers uncommented. Your submission should run without errors.
  4. Follow instructions carefully:
    • If you do not fork/clone and set up your file structure correctly you will not receive credit
    • If you do not follow the commit instructions precisely you will not receive credit
    • If code for your answers is commented out you will not receive credit

Combine objects, arrays, and functions

COMPLETE ANY 3

  1. Create an object that has a property that is an array. Log one of the elements of that array.
  2. Create an object that has a property that is an object. Log one of the properties of that inner object.
  3. Create an object that has a property that is a function (method). Call that method.
  4. Create an array that has an object in it. Log one of the properties of that object.
  5. Create an array that has an array as one of its elements. Log one of the elements of the inner array.
  6. Create an array that has a function as one of its elements. Call that function.
  7. Create an object that has a property that is an array. Loop over the array and log each individual element.
  8. 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"

Combine objects, arrays, and functions more than one level deep

COMPLETE ANY 3

  1. 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).
  2. Create a function that returns an array. Log an element of the array.
  3. Create a function that returns an object that has an array. Log one of the elements of that array.
  4. Create a function that returns an object that has an object. Log one of the properties of the inner object.
  5. Create a function that returns an object that has a method. Call that inner function (method).
  6. Create a function that returns a function. Call that inner function
  7. Create an object that has a method that returns an object. Log a property of the inner object.
  8. Create an object that has a method that returns an object that has an array. Log an element of that array.
  9. Create an object that has a method that returns an object that has an object. Log a property of the inner object.
  10. Create an object that has a method that returns an object that has another method. Call the inner method.
  11. Create an object that has a method that returns a function. Call that function.
  12. Create an array that has a function that returns an object. Log a property of the object.
  13. Create an array that has a function that returns an object that has an array. Log an element of the inner array.
  14. Create an array that has a function that returns an object that has an object. Log a property of the inner object.
  15. Create an array that has a function that returns an object that has a method. Call that method.
  16. 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"

Create a callback

  1. Define two functions and set them to variables
  2. The second function takes a parameter
  3. Call the second function, passing in the variable that references the first function as the parameter
  4. 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"

Indentation

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"

Semantic naming of variables

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"

Function definition placement

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"

Commenting code

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"

Describe some common programming principles

Read this article (don't worry it's short): http://www.artima.com/weblogs/viewpost.jsp?thread=331531

Error reading

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"

Coerce data types

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"