Coder Social home page Coder Social logo

phase-0-intro-to-js-2-objects-lab's Introduction

Objects Lab

Learning Goals

  • Create an Object
  • Perform operations on an Object

Introduction

We covered the concepts of Objects 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

phase-0-intro-to-js-2-objects-lab's People

Contributors

aviflombaum avatar curiositypaths avatar dependabot[bot] avatar gj avatar ihollander avatar jasondecastro avatar jeffkatzy avatar jenmyers avatar jlboba avatar jmburges avatar lizbur10 avatar maxwellbenton avatar professor-ben avatar rrcobb avatar sgharms avatar thuyanduong-flatiron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

phase-0-intro-to-js-2-objects-lab's Issues

Timed out running tests

Canvas Link

https://learning.flatironschool.com/courses/5262/assignments/219686?module_item_id=512208

Concern

A student was working through this and it timed out when running learn test, her code matches the solution.

terminal example below;

1) employees updateEmployeeWithKeyAndValue(employee, key, value) "before each" hook for "returns an employee with the original key value pairs and the new key value pair": Error: Timeout of 10000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/Users/ebyanjamal3/Development/phase-0-intro-to-js-2-objects-lab/test/indexTest.js) at listOnTimeout (node:internal/timers:559:17) at processTimers (node:internal/timers:502:7)

Additional Context

No response

Suggested Changes

No response

Submission Error

Canvas Link

https://learning.flatironschool.com/courses/7423/assignments/264126?module_item_id=632570

Concern

`
/home/codegrade/student/node_modules/chai/lib/chai/assertion.js:69
flag(this, 'eql', config.deepEqual ?? util.eql);
^

SyntaxError: Unexpected token '?'
at wrapSafe (internal/modules/cjs/loader.js:915:16)
at Module._compile (internal/modules/cjs/loader.js:963:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Module.require (internal/modules/cjs/loader.js:887:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object. (/home/codegrade/student/node_modules/chai/lib/chai.js:63:17)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Module.require (internal/modules/cjs/loader.js:887:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object. (/home/codegrade/student/node_modules/chai/index.js:1:18)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Module.require (internal/modules/cjs/loader.js:887:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object. (/home/codegrade/student/test/helpers.js:1:14)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Module.require (internal/modules/cjs/loader.js:887:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object. (/home/codegrade/student/test/indexTest.js:1:1)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Module.require (internal/modules/cjs/loader.js:887:19)
at require (internal/modules/cjs/helpers.js:74:18)
at requireOrImport (/home/codegrade/.npm/lib/node_modules/mocha/lib/esm-utils.js:15:12)
at Object.exports.loadFilesAsync (/home/codegrade/.npm/lib/node_modules/mocha/lib/esm-utils.js:28:26)
at Mocha.loadFilesAsync (/home/codegrade/.npm/lib/node_modules/mocha/lib/mocha.js:386:19)
at singleRun (/home/codegrade/.npm/lib/node_modules/mocha/lib/cli/run-helpers.js:149:15)
at exports.runMocha (/home/codegrade/.npm/lib/node_modules/mocha/lib/cli/run-helpers.js:186:11)
at Object.exports.handler (/home/codegrade/.npm/lib/node_modules/mocha/lib/cli/run.js:319:11)
at /home/codegrade/.npm/lib/node_modules/mocha/node_modules/yargs/lib/command.js:241:49
Traceback (most recent call last):
File "/usr/local/bin/cg-mocha", line 8, in
sys.exit(app())
File "/usr/local/lib/python3.7/dist-packages/typer/main.py", line 214, in call
return get_command(self)(*args, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/click/core.py", line 1130, in call
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/click/core.py", line 1055, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.7/dist-packages/click/core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.7/dist-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.7/dist-packages/click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/typer/main.py", line 500, in wrapper
return callback(**use_params) # type: ignore
File "/usr/local/lib/python3.7/dist-packages/cg_at_utils/utils/cli.py", line 140, in _run_wrapper
return run(*args, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/cg_at_utils/_unittest/mocha.py", line 45, in run
fixup_xml(tmp.name).write(xml_loc)
File "/usr/local/lib/python3.7/dist-packages/cg_at_utils/_unittest/mocha.py", line 54, in fixup_xml
for _, el in tree:
File "/usr/lib/python3.7/xml/etree/ElementTree.py", line 1228, in iterator
root = pullparser._close_and_return_root()
File "/usr/lib/python3.7/xml/etree/ElementTree.py", line 1275, in _close_and_return_root
root = self._parser.close()
xml.etree.ElementTree.ParseError: no element found: line 1, column 0`

Additional Context

No response

Suggested Changes

No response

Driver needs to be changed to employee

Thanks for raising this issue! Future learners thank you for your diligence. In
order to help the curriculum team address the problem, please use this template
to submit your feedback. We'll work on addressing the issue as soon as we can.

Please fill out as much of the information below as you can (it's ok if you
don't fill out every section). The more context we have, the easier it will be
to fix your issue!

Note: you should only raise issues related to the contents of this lesson.
If you have questions about your code or need help troubleshooting, reach out to
an instructor/your peers.


both the tests and the instructions refer to the creation of driver objects. However, the code needs to create new employee objects. I think this is throwing some students for a loop.

Link to Canvas

unfortunately, I do not have access to Canvas material.

Add a link to the assignment in Canvas here.

What should be changed?

Suggest your change here. Let us know what section or line of the Readme needs
to be updated, and any proposed corrections. Include the line number(s) if
possible.

Additional context

Add any other context about the problem here.

once again, very frustrating

For this lesson in particular, I still don't understand if we are actually going to be writing obj, key, and value whenever we are writing real code, or if those are just placeholders to help you see and learn where they go.

If the latter is true, then I feel it would have been more beneficial to learn this in the lesson, especially for people who are brand new to coding, like me. I would have rather seen this code explained to me in the lesson, and then the mondayMenu explainations to relate to it. Then maybe for the test make an employee list of my own with corrections ect.. I went in thinking that this would be the case, kind of like how the lesson showed you ie. mondayMenu tuesdayMenu ect.. but again like in previous lessons, the instructions weren't super clear to me.

I still have to look up pretty much everything on slack after my fifth attempt of looking at instructions and going back into the lesson and seeing almost no relevance to what the test wants. It is really frustrating and time consuming. I don't really feel like I'm prepared for these tests.

Also, I'm still irked with how we're supposed to look at the index test.js and just "know" what it is were supposed to do. It's just not easy to read for me with the little info that was explained about it. I feel like no brand new coder is having an easy time with this. I want to learn, practice, and be confident with the material first before I test on my own without instructions. If the instructions were on the lesson, walking you through what to do, I think that would be wayyyy more helpful and less stressful.

Description of 'employee' Object setup seems inaccurate. (Grammar?)

Canvas Link

https://learning.flatironschool.com/courses/5506/assignments/170669?module_item_id=371063

Concern

Grammar here seems inaccurate:
To start, define a employee variable and assign it to an Object containing name and streetAddress keys;

This sounds like we are assigning a variable to an Object. But don't we assign stuff to variables? That is, it seems like we should be assigning an Object to the variable 'employee', and the Object should have keys of 'name' and 'streetAddress'.

Additional Context

No response

Suggested Changes

Maybe rephrase above to:

To start, define a employee variable and assign an Object to it that has keys of name and streetAddress;

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.