From 40fa864a846e6e127bd966486f656c07f2873288 Mon Sep 17 00:00:00 2001 From: Valerii49 Date: Sat, 9 Dec 2023 20:36:13 +0100 Subject: [PATCH] done A tiny JS world --- submissions/Valerii49/tiny-js-world/index.js | 80 ++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 submissions/Valerii49/tiny-js-world/index.js diff --git a/submissions/Valerii49/tiny-js-world/index.js b/submissions/Valerii49/tiny-js-world/index.js new file mode 100644 index 0000000000..b897f9a921 --- /dev/null +++ b/submissions/Valerii49/tiny-js-world/index.js @@ -0,0 +1,80 @@ +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
. 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('ABC');
+	print('ABC', 'div');
+
+	print('human; John; male; 2; 2; Hello world!; Rex, Tom, Jenny');
+	print('human; John; male; 2; 2; Hello world!; Rex, Tom, Jenny');
+	print('human; John; male; 2; 2; Hello world!; Rex, Tom, Jenny', 'div');
+	*/
+const dog = {
+	species: 'dog',
+	name: 'Rex',
+	gender: 'male',
+	legs: 4,
+	hands: 0,
+	saying: 'woof-woof!'
+};
+const cat = {
+	species: 'cat',
+	name: 'Muca',
+	gender: 'female',
+	legs: 4,
+	hands: 0,
+	saying: 'Mijau-mijau!'
+}
+const man = {
+	species: 'human',
+	name: 'Arnold',
+	gender: 'male',
+	legs: 2,
+	hands: 2,
+	saying: "I'll be back"
+}
+const woman = {
+	species: 'human',
+	name: 'Scarlett',
+	gender: 'female',
+	legs: 2,
+	hands: 2,
+	saying: "I'll think about it tomorrow",
+	friends: man.name
+}
+const catwoman = {
+	species: 'human',
+	name: 'Selina',
+	gender: 'female',
+	legs: 2,
+	hands: 2,
+	saying: cat.saying
+}
+man.friends = woman.name;
+
+const folks = [dog, cat, man, woman, catwoman];
+const objKeys = ["species", "name", "gender", "legs", "hands", "saying", "friends"];
+
+folks.forEach(item => {
+	print(objKeys.reduce((resStr, key) =>
+		resStr += `${key}: ${item[key]};  `, ''));
+});
\ No newline at end of file