-
-
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 6 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,106 @@ | ||
/* 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'] | ||
const allCharactersArray = [catWoman, male, female, cat, dog] | ||
|
||
// function printObjectNew(personToPrint){ | ||
// const propToPrint = []; | ||
// prop.forEach((propOfObj) => { | ||
// propToPrint.push(personToPrint[propOfObj]); | ||
// }) | ||
// let newStr = propToPrint.join('; '); | ||
// print(newStr); | ||
// } | ||
|
||
function arrayToString(propToPrint){ | ||
let newStr = propToPrint.join('; '); | ||
console.log(propToPrint); | ||
print(newStr); | ||
} | ||
|
||
function arrayOfPropToPrint(personToPrint){ | ||
const propToPrint = []; | ||
prop.forEach((propOfObj) => { | ||
propToPrint.push(personToPrint[propOfObj]); | ||
}) | ||
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. A perfect use case for 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 done |
||
arrayToString(propToPrint); | ||
} | ||
|
||
function printAllObjects(arrayAllObjects){ | ||
arrayAllObjects.forEach((characters) => { | ||
arrayOfPropToPrint(characters); | ||
}) | ||
} | ||
|
||
printAllObjects(allCharactersArray); | ||
|
||
// 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. Make your code editor to ensure you always have an empty line at the end of file. There must be a setting. Check 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. Thank you! Done |
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.
This function promises to convert an array to a string but it also prints.
Also remove calls to
console
before submitting code.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.
done