Skip to content

Commit

Permalink
A tiny JS world task (#414)
Browse files Browse the repository at this point in the history
* A tiny JS world task

* Change forEach method on map

* Fix bugs

* Rename function params
  • Loading branch information
deveLabR authored Sep 23, 2022
1 parent d9260be commit 9f9982a
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions submissions/develabr/js-pre-oop/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
const cat = {
species: 'cat',
name: 'Kitty',
gender: 'female',
legs: 4,
hands: 0,
saying: 'meow!',
friends: ["cats don't needs any friends"],
};

const catWoman = Object.create(cat);
catWoman.species = 'human';
catWoman.name = 'Catwoman';
catWoman.gender = 'female';
catWoman.legs = 2;
catWoman.hands = 2;
catWoman.friends = [cat.name];

const woman = {
species: 'human',
name: 'Selina Kyle',
gender: 'female',
legs: 2,
hands: 2,
saying: 'Hello, Batman. Do you know Catwoman?',
friends: [cat.name, catWoman.name],
};

const man = {
species: 'human',
name: 'Bruce Wayne',
gender: 'male',
legs: 2,
hands: 2,
saying: "Hi! I'm Batman",
friends: [catWoman.name, woman.name],
};

const dog = {
species: 'dog',
name: 'Spike',
gender: 'male',
legs: 4,
hands: 0,
saying: 'woof-woof!',
friends: [woman.name, man.name],
};

const persons = [dog, cat, man, woman, catWoman];

const attributes = [
'species',
'name',
'gender',
'legs',
'hands',
'saying',
'friends',
];

function personInfoItems(person) {
return attributes.map((key) => person[key]).join('; ') + '.';
}

persons.map((person) => print(personInfoItems(person)));

0 comments on commit 9f9982a

Please sign in to comment.