BeginnerCoder

Lesson 2 — Variables

Storing values

A variable is a labelled box that remembers a value so you can reuse it. Create one with name = value, then use the name anywhere you need that value.

Why it matters: variables let your program hold on to data — a user name, a score, a total — and change it as the program runs.

Tip: the = sign means "store into", not "equals". Read x = 5 as "put 5 into x".

Want it another way?
Task

Change the variable so the program prints: Hello, Sam

Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.