+ 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
7 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');
+ 3
I think all awesomeđ
+ 3
its already coolđđ
maybe change all the lime text to limegreen or lawngreen
+ 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
+ 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.
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.