Before writing any code, you need to know where to put it and how to test it. Good news: everything you need is already in your browser.
Where to put your JavaScript
- In a separate file (recommended): a script.js file linked with the tag
<script src="script.js"></script>. - Directly in the HTML: between
<script>tags, usually just before the closing</body>.
The browser console
The console is the JavaScript developer’s tool of choice. Open it with the F12 key (or right-click → « Inspect »), then pick the Console tab. You can type code there and see the result straight away.
The most useful command is console.log(): it prints a value in the console. It is your best ally for understanding what your program is actually doing.
Key takeaway: the console (F12) is where you test code and print messages with
console.log(). Keep it open while you work.