Step 1 of 9
JavaScript exercises for beginners: how this lesson works
In this lesson you practise JavaScript with exercises for beginners: variables, functions, arrays and the DOM, ending with a button you wire up yourself. Every exercise runs in the step: you type code, press Run, and the lesson checks each task as you go.
JavaScript is the language every web browser runs. It turns a page that only shows things into a page that does things: a cart that counts, a form that checks itself, a button that answers. The block below is a taste of where you'll be at the end. The code on the left really runs. Press Add to cart and watch which lines light up.
In this lesson you'll:
- store values in variables with
letandconst, and see why the difference matters; - work with numbers, strings and template literals, and make decisions with
if; - write functions that take inputs and
returna result, and loop over an array of sales; - find elements on a page, change their text, and run code when a button is clicked.
It takes about 75 minutes. Each hands-on step has a small editor with tasks above it. A task turns green when the code does what it asks, and every task has a Hint.
How to read the output: console.log(x) prints x in the Console output box. Text prints as it is, a list prints like [ 1, 2, 3 ], and an error prints in red with the line it stopped on.
Takeaway: JavaScript reads values, changes them and reacts to the page. You'll write each piece of that yourself.