Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

emanelbaradei
emanelbaradei
11,395 Points

shout app - Is it wrong to make it just one line instead of breaking it to several lines?

i made it on one line only and it worked the same way:

alert(prompt("say a shout").toUpperCase() + "!!!");

is it a better practice to break code to several lines?

1 Answer

Jaroslaw Adamowicz
Jaroslaw Adamowicz
11,634 Points

Hi, I think that answer should be: it depends.

In your case:

alert(prompt("say a shout").toUpperCase() + "!!!");

I can easily read it from left to right and quickly grasp what code is doing, so I think it is alright.

But for sure you may find one liners that will be total overkill and very hard to understand, as example:

[].forEach.call($$("*"),function(a){
  a.style.outline="1px solid #"+(~~(Math.random()*(1<<24))).toString(16)
})

It still not that bad if you know it is CSS realated and are quite efficient with JS whatsoever, but you can clearly see where it goes and how hard it can be for someone still learning his craft...

you can find article related to code above here

Cheers!