GithubHelp home page GithubHelp logo

week-2-assessment's Introduction

Week 2 Assessment - NAME: ____________ __/20

Put your answers in the provided answers.txt

Conceptual


let color = 'yellow';

let crimeFighters = {
  turtles: ["Leonardo", "Raphael", "Michelangelo", "Donatello"],
  rangers: {
    red: "Jason",
    black: "Zack",
    yellow: "Trini",
    blue: "Billy",
    pink: "Kimberly",
    green: "Tommy"
  }
};

if (crimeFighters.rangers.red === 'Jason') crimeFighters.rangers.blue = 'Bob';

Assuming the above code has been run:

1. What does the expression crimeFighters.turtles[3] return?

2. What does the expression crimeFighters.rangers[color] return?

3. What does the expression crimeFighters.rangers.blue return?
let b = "cat";
let a = "dog";
a = b;
a === "duck"

Assuming the above code has ran:

4. What is the value of a?

const myFunc = function() {
  "hello world";
};
console.log(myFunc)
5. The student that wrote the code above expected "hello world" to log in the console. Explain what change(s) are needed to make the code work as expected - without console.log being added within the myFunc function?




let stuff = [
  ['one', 2, false],
  {
	apples: 12,
	fn: function() { return this.apples; }
  },
  false
];

let a = 2;

Assuming the above code has ran:

6. What does the expression stuff[a] evaluate to?

7. What does the expression stuff[0][a] evaluate to?

8. What does the expression stuff[0][1] evaluate to?

9. What does the expression stuff[1].fn() return?

Mechanical


Array Iteration

1. Declare a variable named turtles and assign an array containing the strings "Donatello", "Leonardo", "Michelangelo", and "Raphael":



2. Write a forEach loop to console.log each name in turtles, appending the string " likes pizza" to each name:



Classes

  class Turtle {
      constructor(name, maskColor) {
      		// Question 3 answer below
          name: "",
          maskColor: "";
      }
      // add the sayName method below (Question 4)
      function sayName(name) {
        console.log(`I am ${name}`);
      }
    
    
    
  }
  
  // Create a new Turtle object below (Question 5)
  
  let leo = new Turtle("Leonardo", "Blue");
  
  

Complete the following code inside of the Turtle class above:

3. Such that new turtle objects created will have their name and maskColor properties assigned.
4. Add a sayName method that console.logs “I am " and appending the turtle's name.
5. Write the line of code above that uses the Turtle class above to create a turtle object with a name of "Leonardo" and a maskColor of "blue"; and assign the new object to a variable named leo.

Objects

let car = {make: 'Toyota', year: 2017, model: 'Prius'};
6. Write a JS expression (just the expression, don't assign to a variable) that accesses the value of the car object's model property using dot notation:

7. Write a JS expression that accesses the value of the car object's year property using square bracket notation:

8. Define an object literal and assign to a variable named account. Within the object literal, include an accountNo property that holds a string of your choosing and a balance property that holds a number of your choosing. Finally, include a method (property that holds a function) named print within the object literal that would console.log a string formatted as
      Account No: AAAAAA / Balance: BBBBB
substituting the values of accountNo and balance for AAAAAA and BBBBB:





Functions and Callbacks

9. Write a function named add that has two parameters and RETURNS the sum of those two parameters:



10. Write a function named calculate that accepts three arguments: two numbers and a callback function. Code the calculate function such that it will RETURN the result returned from invoking the callback function with the two numbers as arguments:




11. Invoke the calculate function (defined in question #10 above), passing to it these arguments: 20, 15, and the add function (defined in question #9 above):



week-2-assessment's People

Contributors

gndm avatar weston-bailey avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.