-
-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New index.js for tiny js task (#258)
* New index.js for tiny js task * work with an array instead of an object, change name of variables and function * Update index.js * Update index.js * change function * new change for tiny-js * New function for print
- Loading branch information
Showing
1 changed file
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* 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. | ||
*/ | ||
|
||
const allCharactersArray = [catWoman, male, female, cat, dog] | ||
|
||
function arrayOfPropToPrint(personToPrint){ | ||
const prop = ['species', 'name', 'gender', 'legs', 'hands', 'saying', 'friends'] | ||
const propToPrint = prop.map((propOfObj) => personToPrint[propOfObj]); | ||
let newStr = propToPrint.join('; '); | ||
print(newStr); | ||
} | ||
|
||
function printAllObjects(arrayAllObjects){ | ||
arrayAllObjects.forEach((characters) => { | ||
arrayOfPropToPrint(characters); | ||
}) | ||
} | ||
|
||
printAllObjects(allCharactersArray); |