Ready. Start with one instruction.
Loading the learning workspace…
FROM YOUR FIRST INSTRUCTION TO A WORKING APPLICATION
Learn JavaScript from scratch through small working examples, visual experiments and complete projects. No account or AI key required.
Predict → Experiment → Build → Test → Explain
Ready. Start with one instruction.
Loading the learning workspace…
An id identifies a particular element in a document and should be unique. getElementById accepts the identifier without a # prefix; querySelector accepts a CSS selector such as #status. Both can return null when nothing matches. Store the element in a descriptive variable so later changes are easy to understand. Avoid relying on automatic window properties created from ids. A selector is a string describing a match. The # prefix selects an ID. querySelector can return null when nothing matches.
const status = document.getElementById('status');
status.textContent = 'Ready';Run the preview tests; inspect the live page.
An id identifies a particular element in a document and should be unique. getElementById accepts the identifier without a # prefix; querySelector accepts a CSS selector such as #status. Both can return null when nothing matches. Store the element in a descriptive variable so later changes are easy to understand. Avoid relying on automatic window properties created from ids.
const status = document.getElementById('status');Declare status with const. The binding cannot be reassigned. The expression after = supplies its initial value; = is assignment, not an equality comparison.
status.textContent = 'Ready';Read or update literal text in the selected element. It does not parse user input as HTML.
const status = document.getElementById('status');
status.textContent = 'Ready';
console.log(document.querySelectorAll("*").length);Interact with the preview; the diagnostic displays its actual element count.
An id identifies a particular element in a document and should be unique. getElementById accepts the identifier without a # prefix; querySelector accepts a CSS selector such as #status. Both can return null when nothing matches. Store the element in a descriptive variable so later changes are easy to understand. Avoid relying on automatic window properties created from ids. A selector is a string describing a match. The # prefix selects an ID. querySelector can return null when nothing matches. The final diagnostic counts actual matching elements. Read querySelectorAll as a selection and length as the collection count.
const status = document.getElementById('status');Declare status with const. The binding cannot be reassigned. The expression after = supplies its initial value; = is assignment, not an equality comparison.
status.textContent = 'Ready';Read or update literal text in the selected element. It does not parse user input as HTML.
console.log(document.querySelectorAll("*").length);Evaluate the argument and display its value at this point. Quoted text is literal; an unquoted identifier reads its current binding.
const status = document.getElementById('status');
status.textContent = 'Ready';
console.log(document.querySelectorAll("button").length);Interact with the preview; the diagnostic displays its actual element count.
An id identifies a particular element in a document and should be unique. getElementById accepts the identifier without a # prefix; querySelector accepts a CSS selector such as #status. Both can return null when nothing matches. Store the element in a descriptive variable so later changes are easy to understand. Avoid relying on automatic window properties created from ids. A selector is a string describing a match. The # prefix selects an ID. querySelector can return null when nothing matches. The final diagnostic counts actual matching elements. Read querySelectorAll as a selection and length as the collection count.
const status = document.getElementById('status');Declare status with const. The binding cannot be reassigned. The expression after = supplies its initial value; = is assignment, not an equality comparison.
status.textContent = 'Ready';Read or update literal text in the selected element. It does not parse user input as HTML.
console.log(document.querySelectorAll("button").length);Evaluate the argument and display its value at this point. Quoted text is literal; an unquoted identifier reads its current binding.
Use getElementById to change #status to Ready.
// Use getElementById to change #status to Ready. // Write your JavaScript below.
const status = document.getElementById('status');
status.textContent = 'Ready';getElementById("status") selects this paragraph.
Which operation changed the result, why did it work, and what would you test next?
Use a different value that could expose a boundary or mistake. Predict the result first, run it, and explain how the concept would help in a small real application.
Related: Previous lesson Next lesson
100 lessons across 20 modules, covering variables, operators, strings, conditions, loops, functions, scope, arrays, objects, DOM, events, state, testing, asynchronous JavaScript and application development.