Skip to content

Accelerator-One-Days-Track-1/labs-objects

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

Accelerator Track One

JavaScript Object Drills

In this section, you'll practice creating, accessing, modifying, and working with objects in JavaScript. You'll write programs that solve problems by manipulating object properties and methods, as well as working with nested objects and arrays of objects.

Instructions:

In objects.js, for each prompt, write a JavaScript program that solves the problem using objects. Make sure to run the program in your terminal to check if it works as expected.


Object Basics

  1. Create a Simple Object
    Write a program to create an object named car with properties make, model, and year. Print the object.

  2. Access Properties
    Write a program that prints the make and model properties of the car object.

  3. Add a New Property
    Add a color property to the car object and print the updated object.

  4. Delete a Property
    Delete the year property from the car object and print the updated object.

  5. Modify a Property
    Update the color property in the car object to "red" and print the updated object.

  6. Check for Property
    Write a program to check if the car object has a doors property. Print true or false.

  7. Iterate Through an Object
    Use a for...in loop to print all the keys and values in the car object.


Nested Objects

  1. Create a Nested Object
    Create an object book with properties title, author, and details. The details property should be another object containing publisher and year. Print the object.

  2. Access Nested Properties
    Write a program to print the publisher and year of the book object.

  3. Modify Nested Properties
    Update the year property inside details of the book object to the current year. Print the updated object.

  4. Add Nested Properties
    Add a new property pages to the details object inside book. Set it to 350 and print the updated object.

  5. Delete Nested Properties
    Delete the publisher property from the details object inside book. Print the updated object.


BONUS: Arrays of Objects

  1. Create an Array of Objects
    Create an array students with three objects, each representing a student. Each object should have properties name, age, and grade. Print the array.

  2. Access Objects in Array
    Write a program to print the name of the second student in the students array.

  3. Modify an Object in an Array
    Update the grade of the first student in the students array to "A". Print the updated array.

  4. Add a New Object to the Array
    Add a new student object to the students array and print the updated array.

  5. Remove an Object from the Array
    Remove the last student object from the students array and print the updated array.


SUPER BONUS: Advanced Object Operations

  1. Copy an Object
    Use the spread operator to create a copy of the car object and modify its make property. Print both the original and the copied object.

  2. Merge Two Objects
    Create two objects, person and job, with some properties. Merge them into a new object and print it.

  3. Object Methods
    Create an object calculator with methods add, subtract, multiply, and divide. Each method should take two numbers as arguments and return the result. Use the calculator object to perform operations and print the results.


Submission:

  • Complete all drills in the file.
  • Push your work to your forked copy, create a pull request on the original repo, and then submit your URL on Google Classroom.
  • Be prepared to explain how your code works.

Happy coding and good luck! 🚀

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published