Skip to content
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

a tiny js world #593

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Next Next commit
added file for a tiny js world task
  • Loading branch information
SableVector committed Sep 10, 2022
commit dc5ed4201093ea4018bc7ccd3be6a8d72e7a8e2f
91 changes: 91 additions & 0 deletions submissions/SableVector/tiny-js-world-task/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
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: _put repo URL here_
Web app: _put project's github pages URL here_
*/

// ======== OBJECTS DEFINITIONS ========
// Define your objects here


// ======== 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.
*/

/* Print examples:
print('ABC');
print('<strong>ABC</strong>');
print('<strong>ABC</strong>', 'div');

print('human; John; male; 2; 2; Hello world!; Rex, Tom, Jenny');
print('human; <strong>John</strong>; male; 2; 2; <em>Hello world!</em>; Rex, Tom, Jenny');
print('human; <strong>John</strong>; male; 2; 2; <em>Hello world!</em>; Rex, Tom, Jenny', 'div');
*/


const inhabitants = {
dog: {
species: 'dog',
legs: 4,
hands: 0,
name: 'Rex',
gender: 'male',
saying: 'woof-woof!'
},
cat: {
species: 'cat',
legs: 4,
hands: 0,
name: 'Roxi',
gender: 'famale',
saying: 'meow-meow!'
},
woman: {
species: 'woman',
hands: 2,
legs: 2,
name: 'Jenny',
gender: 'famele',
saying: 'Hello Jenny'
},
man: {
species: 'man',
hands: 2,
legs: 2,
name: 'John',
gender: 'famele',
saying: 'Hello John'
},
catwoman: {
species: 'cat-woman',
legs: 2,
hands: 2,
name: 'Jesika',
gender: 'female',
}
}

inhabitants.catwoman.saying = inhabitants.cat.saying;

for (let person in inhabitants) {
const message = getPersonData(inhabitants[person]);

print(message, 'h2');
}

function getPersonData(person) {
let str = '';

for (let option in person) {
str += person[option] + '; ';
}

return str;
}