Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New index.js for tiny js task #258

Merged
merged 8 commits into from
Aug 25, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions submissions/Levi123/tiny-JS/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/* Refer to https://github.com/OleksiyRudenko/a-tiny-JS-world for the task details
Complete the below for code reviewers' convenience:

Code repository: https://github.com/Levi123/a-tiny-JS-world
Web app: _put project's github pages URL here_
*/

// ======== OBJECTS DEFINITIONS ========
// Define your objects here
const dog = {
species: 'dog',
name: 'Rich',
gender: 'male',
legs: 4,
hands: 0,
saying: 'Hav-hav!',
friends: ['Bonya'],
}

const cat = {
species: 'cat',
name: 'Bonya',
gender: 'female',
legs: 4,
hands: 0,
saying: 'Mr-mr-mr',
friends: ['Rich', 'Catwoman'],
}

const female = {
species: 'human',
name: 'Olya',
gender: 'female',
legs: 4,
hands: 4,
saying: "Glory to Ukraine",
friends: ['Yura', 'Rich'],
}

const male = {
species: 'human',
name: 'Yura',
gender: 'male',
legs: 4,
hands: 4,
saying: "Glory to Ukraine",
friends: ['Olya', 'Bonya'],
}

const catwoman = {
species: 'human',
name: 'Catwoman',
gender: 'female',
legs: 4,
hands: 4,
saying: cat.saying,
friends: ['Bonya']
}
// ======== OUTPUT ========
/* Use print(message) for output.
Default tag for message is <pre>. Use print(message,'div') to change containing element tag.

Message can contain HTML markup. You may also tweak index.html and/or styles.css.
However, please, REFRAIN from improving visuals at least until your code is reviewed
so code reviewers might focus on a single file that is index.js.
*/

function printObject(object){
const prop = [];
for (element in object){
prop.push(object[element]);
}
let newStr = prop.join('; ');
print(newStr);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Give variables and functions meaningful names. Avoid generic names like item, element, key, object, array or their variations. Exception: helper functions that are specifically and intentionally designed to be multipurpose.
  • Object methods like keys, values, entries shouldn't be used when a particular order is required as these do not guarantee any particular order of keys/values. Same refers to for...of and for...in when applied to objects.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Give variables and functions meaningful names. Avoid generic names like item, element, key, object, array or their variations. Exception: helper functions that are specifically and intentionally designed to be multipurpose.
  • Object methods like keys, values, entries shouldn't be used when a particular order is required as these do not guarantee any particular order of keys/values. Same refers to for...of and for...in when applied to objects.

I don't understand second point of your massage, i can't use (for...in) at all? and why?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: I can't use (for...in) at all? and why?

A: As per explanation above "...when a particular order is required as these do not guarantee any particular order of keys/values."

Only arrays guarantee order of elements.

As a peer developer, knowing that in objects order of keys is not important I can define new objects with properties in different order. It would be great if this didn't affect the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: I can't use (for...in) at all? and why?

A: As per explanation above "...when a particular order is required as these do not guarantee any particular order of keys/values."

Only arrays guarantee order of elements.

As a peer developer, knowing that in objects order of keys is not important I can define new objects with properties in different order. It would be great if this didn't affect the code.

I try to change my errors.


printObject(catwoman);
printObject(male);
printObject(female);
printObject(cat);
printObject(dog);