Building web pages is an exciting way to develop coding skills, but with so many terms to learn it can be overwhelming to start out.
JS, along with HTML and CSS provides the code for the parts of the website that the user sees and interacts with. To get specific, HTML gives the page structure, whilst CSS makes it look pretty, and JS makes it interactive.
The cake analogy
You can think about the HTML, CSS and JS trio as being layers of a cake. HTML is the basic sponge; you can have a web page using only HTML but it would be very boring, and ugly, like a plain sponge. CSS is the icing: it makes the cake look pretty, but doesn’t add much substance to it. Finally, JS is the filling, it gives the webpage that wow factor. You can add both the CSS and JS into the HTML sponge, or you can write them in separate files, making the code a bit tidier. Both methods work well, and both have their advantages.
Store useful information in variables. For example, you might store a password entered by the user into a variable for a while, before checking if it’s correct.
Perform operations on numbers and strings.
Carry out code when an ‘event’ occurs, for example when somebody clicks a button.
Define functions. Like in other programming languages such as Python, you can define a block of code (a function), that is ‘called’ by several different events. This allows you to reuse the code that you wrote for the function.
Article written by Britt Dewing, Stemettes Intern