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 trialPaul Messmer
15,023 PointsCan you create a website in JS alone?
I have yet to finish this course but, in theory could you code in entire website in JS by adding HTML to the website through JavaScript?
2 Answers
Adam Duffield
30,494 Points100% possible, JavaScript is very advanced nowadays.
If it's a pretty looking frontend site with very little functionality e.g. just text & images, maybe a modal & a mobile menu. You can easily build a site in just html, css & JS. If your website requires say for example a blog, or your developing an API for a website to collect data from you can use server side JavaScript such as Node.js to handle the "backend code" & yet still use Html, Css & JS to develop the frontend of a website.
JS is probably one of the most flexible languages. You can create websites, API's, Desktop Applications & Mobile Apps in JS.
UPDATE... I just re-read the question... You could build a fully fledged html site by passing the html in JavaScript files (I'm assuming you mean by creating elements & appending them). But i seriously would not recommend it, it would look very ugly, very quickly & be harder to manage because of it. Once you begin to play with JavaScript frameworks you will see that it can be handled in multiple different easier ways but generally, leave html to do the job of html.
Adam
Steven Parker
231,269 PointsI assume you mean adding HTML to the page inside the browser. You nearly could, but it takes a little bit of HTML code to load in the JavaScript to begin with. But it would still be extremely labor-intensive compared to writing HTML directly.
You could, however, generate the HTML at the server end using JavaScript and the node.js engine. So in that sense, yes, you could have an entire site written in JS.