+ 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
7 Respostas
+ 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
ŐŐžÖ†Ő«
+ 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