Help me make this spagetti code look better. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 8

Help me make this spagetti code look better.

These functions are supposed to create a post and all that is required is to call the function, so all the css of the elements must be in the functions. The problem is, the functions look awful. What should I do? https://code.sololearn.com/Wa12a185A9A1/?ref=app

31st Dec 2020, 11:22 AM
🍇 Alex Tușinean 💜
🍇 Alex Tușinean 💜 - avatar
6 Answers
+ 6
You don't need to hardcode the styling in JavaScript. Just style in CSS with a class name, then in JavaScript, after element is created with createElement, you can either use El.className = 'classname'; or classlist API El.classlist.add('classname');
31st Dec 2020, 12:42 PM
Gordon
Gordon - avatar
+ 3
I think all awesome😊
31st Dec 2020, 11:45 AM
Սոֆի Մովսեսյան
Սոֆի Մովսեսյան - avatar
+ 3
its already cool👏👏 maybe change all the lime text to limegreen or lawngreen
31st Dec 2020, 11:59 AM
Atoms~⚛
Atoms~⚛ - avatar
+ 2
💜 Alex Tușinean 🍇 [ Inactive ] One suggestion don't call function multiple times. Just create a common function and call other functions randomly. See here: https://code.sololearn.com/WLBbOfB70Tr4/?ref=app
31st Dec 2020, 2:34 PM
A͢J
A͢J - avatar
+ 1
My goal was making a js function that handles everything. But my code looks awful, so I may write the style where it belongs, in css section.
31st Dec 2020, 1:16 PM
🍇 Alex Tușinean 💜
🍇 Alex Tușinean 💜 - avatar
0
I would also rewrite creation of elements in JS to directly into HTML. That way you just apply stuff with js, less code,more structured code that way. Way more isolation of languages.
1st Jan 2021, 11:56 PM
Bogdan Parubok
Bogdan Parubok - avatar