Skip to content
New issue

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

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

Already on GitHub? # to your account

tiny-js-world task #615

Merged
merged 1 commit into from
Sep 20, 2022
Merged
Changes from all commits
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
66 changes: 66 additions & 0 deletions submissions/Anatolii-Petrenko/tiny-js-world/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { print } from "./js/lib.js";
/* 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/Anatolii-Petrenko/a-tiny-JS-world
Web app: https://anatolii-petrenko.github.io/a-tiny-JS-world/
*/

// ======== OBJECTS DEFINITIONS ========
const man = {
species: "human",
name: "Antony",
gender: "male",
hands: 2,
legs: 2,
saying: "Hi Bro!",
};

const woman = {
species: "human",
name: "Jeeny",
gender: "female",
hands: 2,
legs: 2,
saying: "Hello! How it's going?",
};

const dog = {
species: "dog",
name: "Toby",
gender: "male",
hands: 0,
legs: 4,
saying: "Woof-Woof!",
};

const cat = {
species: "cat",
name: "Bella",
gender: "female",
hands: 0,
legs: 4,
saying: "Meow!",
};

const catWoman = {
species: "human",
name: "JeenyCat",
gender: "female",
hands: 2,
legs: 2,
saying: cat.saying,
Copy link
Member

Choose a reason for hiding this comment

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

Notice that this will create a copy of the saying. So when we change a cat's saying, cat-woman won't get updated.

};
// ======== OUTPUT ========
const inhabitants = [man, woman, dog, cat, catWoman];
const inhabitantsKeys = [
"species",
"name",
"gender",
"hands",
"legs",
"saying",
];
inhabitants.map((inhabitant) => {
print(inhabitantsKeys.map((key) => key + ":" + inhabitant[key]).join("\n"));
});