Skip to content

Week 4: JavaScript Objects

Reid Russom edited this page Mar 11, 2024 · 10 revisions
Week Topic Learning Objectives Key Resources
4 JavaScript Objects Students will be able to create, access, destructure, and manipulate JavaScript objects. Week 4 Slides

Overview

JavaScript Fundamentals Part 5: Object Basics

  • Objects
    • Key-value pairs for storing data
    • Accessing properties
    • Using operators

Note that if students are using the Scrimba videos, they only need to watch the first four!

Guidance for Mentors

  • Objects
    • Students may struggle with object syntax at first. Encourage them to practice creating objects, accessing properties, etc.
    • Explain the difference between dot and bracket notation for accessing properties clearly. Students often mix these up initially.

Assignment Rubric

You can mark the student's assignment as complete if they:

  • Fork the Replit file and submit their own link.
  • Use proper syntax and good JavaScript logic to answer the questions. Example outputs (Note that some student work variation is expected!):

Question 1:

const myPet ={
  name: "Max",
  species: "Dog",
  color: "Brown"
};

console.log("Q1 name: ", myPet.name);
console.log("Q1 species: ", myPet.species);
console.log("Q1 color: ", myPet.color);

Question 2:

const aboutPet = `${myPet.name} is a ${myPet.color} ${myPet.species}.`;

console.log("Q2: ", aboutPet);

Question 3:

myPet.age = 3;
myPet.getAge = function(){
  return this.age
};

console.log("Q3: ", myPet.getAge());

Question 4:

function isDog(obj){
  const speciesChecker = "dog";
  return obj.species === speciesChecker;
}

console.log("Q4: ",isDog(myPet));

Question 5:

const library =[
  {
    title: "The Odyssey",
    author: "Homer",
    libraryID: 1234
  },
  {
    title:"Slouching Towards Bethlehem",
    author:"Joan Didion",
    libraryID: 2345
  },
  {
    title:"Love in the Time of Cholera",
    author:"Gabriel Garcia Marquez",
    libraryID: 3456
  }
];

function sortArray(arr){
  return arr.toSorted((a, b) => a.libraryID - b.libraryID);
}

console.log("Q5: ",sortArray(library));
console.log("Q5 original array:  ", library);

Question 6:

function addTypeProperty(arr) {
  return arr.map(item => {
    item.type = 'book';
    return item;
  })
}

Question 7:

function addNewObject(library, newObject) {
  const newKey = `book${Object.keys(library).length + 1}`; 
  library[newKey] = newObject; 
  return library;
}

console.log("Q7: ", addNewObject(library,{title:'JavaScript: The Definitive Guide',author:'David Flanagan',libraryID: 6248}));

Key Pages

Overview of the wiki.

Onboarding guide for new volunteers.

Links to pages for specific assignments, including rubrics, overviews of student content, and mentor-created resources.

Clone this wiki locally