Let’s Write Some JavaScript Right Now!

I find the best way to get started with anything is to be given a safe playground in which to play with some basic rules and then be left alone to play (with some intervention every now and then). So here goes!

Open Sublime Text 3. Create a new file. Save it as index.html. Add the following code to it, save it, and drag the file into Google Chrome:

When the file is open in Google Chrome, there should be some instructions on the screen. Open up the console and see what it says.

Write Your Own Code Now!Now try to write your own console.log statements and tinker around with the code in between the <script> and </script> tags! Save the index.html file once you’ve done some playing, and then refresh the page in Chrome.

The ConsoleThe console is a special tool for showing information to developers. You can send messages to it with console.log('some info'); See what the console says when you try to log different things. Try numbers, pieces of text, or doing a bit of math. We’ll learn all about the different data types and what’s possible in future lessons.

See if you get any red errors appearing in the console. You can also write JavaScript in the console and get the browser to run it by pressing the return key. Try this, for example:

window.screen.availHeight or someString

Changing HTMLWe’ll get to changing HTML, changing CSS, and all that fun stuff in the next few days, but play with this in the meantime! Try writing this before the </script> tag or in the console: