Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mosnad-web01/abdulaziz--phase-0-intro-to-js-2-objects-lab
https://github.com/mosnad-web01/abdulaziz--phase-0-intro-to-js-2-objects-lab
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/mosnad-web01/abdulaziz--phase-0-intro-to-js-2-objects-lab
- Owner: Mosnad-Web01
- License: other
- Created: 2024-08-13T11:56:18.000Z (5 months ago)
- Default Branch: master
- Last Pushed: 2024-08-13T11:57:55.000Z (5 months ago)
- Last Synced: 2024-11-14T16:47:57.329Z (2 months ago)
- Language: JavaScript
- Size: 62.5 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Objects Lab
## Learning Goals
- Create an `Object`
- Perform operations on an `Object`## Introduction
We covered the concepts of `Object`s in JavaScript. Now it's time to put the
concepts into practice.If you haven't already, **fork and clone** this lab into your local environment.
Navigate into its directory in the terminal, then run `code .` to open the files
in Visual Studio Code.## Instructions
Follow the steps below, running `npm test` as you go to get additional
information from the tests. Don't forget to run `npm install` first!Let's say we are working on a program that will keep track of a company's
employees. We want to store each `employee` as an `Object`. We're starting
small, so to begin with we'll only keep track of the employee's name and street
address.To start, assign an `employee` variable to an `Object` containing
`name` and `streetAddress` keys; you can use whatever values you like. Use
literal syntax to create your `Object`. Various updates will be applied to this
variable (destructively and non-destructively) in this lab.Once you've initialized the `employee` Object, you'll need to create the
following four functions:- `updateEmployeeWithKeyAndValue()`: this function should take in three
arguments: an `employee` `Object`, a `key` and a `value`. This function should
not mutate the `employee`; it should return a _new_ `Object` that has an
updated `value` for the `key` passed in. **Hint**: use the spread operator!
- `destructivelyUpdateEmployeeWithKeyAndValue()`: this function should work the
same as `updateEmployeeWithKeyAndValue()` but it _should_ mutate the
`employee` `Object` passed in.
- `deleteFromEmployeeByKey()`: this function should take in a `employee`
`Object` and a `key`. It should delete the property with that `key` from the
`employee` `Object`. This should not mutate the original `employee` `Object`;
it should return a _new_ `Object` that doesn't include the identified
key-value pair. **Hint**: use the spread operator!
- `destructivelyDeleteFromEmployeeByKey()`: this function should work the same
as `deleteFromEmployeeByKey()` but it _should_ mutate the `employee` `Object`.As you work on your functions, be sure to think about when to use dot notation
vs. bracket notation.After you have all the tests passing, remember to commit and push your changes
up to GitHub, then submit your work to Canvas using CodeGrade.## Conclusion
In this lab, we practiced creating an `Object` and performing operations on it.
## Resources
- [MDN: Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)