-
-
Notifications
You must be signed in to change notification settings - Fork 184
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
Changes from 4 commits
48c3930
b9bd5ae
bd07097
a8c281d
81127c4
0b91e4c
4ee80fd
40a8c5d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* 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 prop = ['species', 'name', 'gender', 'legs', 'hands', 'saying', 'friends'] | ||
|
||
function printObjectNew(personToPrint){ | ||
const propToPrint = []; | ||
prop.forEach((propOfObj) => { | ||
propToPrint.push(personToPrint[propOfObj]); | ||
}) | ||
let newStr = propToPrint.join('; '); | ||
print(newStr); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Think of converting property names into object's property values, then joining with Use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @OleksiyRudenko did I understand correctly, I need to split this function into several? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Levi123 while looking through your updated code version I started wondering why is it so. I am sorry, I apparently missed one very important word here. The comment above should read
My apologies. We will fix this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
i don't understand you |
||
} | ||
|
||
// function printObject(object){ | ||
// const prop = []; | ||
// for (element in object){ | ||
// prop.push(object[element]); | ||
// } | ||
// let newStr = prop.join('; '); | ||
// print(newStr); | ||
// } | ||
|
||
// printObject(catWoman); | ||
// printObject(male); | ||
// printObject(female); | ||
// printObject(cat); | ||
// printObject(dog); | ||
|
||
printObjectNew(catWoman); | ||
printObjectNew(male); | ||
printObjectNew(female); | ||
printObjectNew(cat); | ||
printObjectNew(dog); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From the checklist above in the thread:
Requirements are always requirements. Double-check yourself against requirements until the principles helping to design a clean code become a habit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A perfect use case for
Array#map
method.Also
prop
is a global variable. Do not use global variables where there is no need, esp. if it is used in a specific function and only there.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@OleksiyRudenko done