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…
This complete example connects state, form submission, rendering and browser persistence. The source owns a project-specific storage key. On startup it parses saved data inside try/catch and validates required record fields. User actions change records, save the serialized collection and render a view using textContent. A storage failure is reported without pretending the data was saved. The sandbox provides an in-memory localStorage adapter; export the project and serve it over HTTP to verify real reload persistence. Browser storage belongs to an origin and is not a secure vault.
const key = 'discovery-project-19';
let records = [];
try { const saved=JSON.parse(localStorage.getItem(key)||'[]'); if(Array.isArray(saved))records=saved.filter(x=>typeof x.id==='string'&&typeof x.title==='string'&&typeof x.done==='boolean'); } catch {}
function save() { try { localStorage.setItem(key,JSON.stringify(records)); } catch { document.querySelector("#status").textContent="Storage unavailable; current session only."; } }
function render() {
const list=document.querySelector('#items'); list.replaceChildren();
const query=document.querySelector('#search').value.toLowerCase();
for(const record of records.filter(x=>x.title.toLowerCase().includes(query))) {
const li=document.createElement('li'),toggle=document.createElement('button'),remove=document.createElement('button');
toggle.textContent=record.title;toggle.dataset.id=record.id;toggle.setAttribute('aria-pressed',String(record.done));
toggle.addEventListener('click',()=>{record.done=!record.done;save();render(); Array.from(document.querySelectorAll('#items button')).find(button => button.dataset.id === record.id)?.focus();});
remove.textContent='Remove '+record.title;remove.addEventListener('click',()=>{records=records.filter(x=>x.id!==record.id);save();render(); document.querySelector('#title').focus();});
li.append(toggle,remove);list.append(li);
}
}
document.querySelector('#form').addEventListener('submit',event=>{event.preventDefault();const field=document.querySelector('#title'),title=field.value.trim();if(!title){document.querySelector('#status').textContent='Enter a task.';return;}records.push({id:crypto.randomUUID(),title,done:false});field.value='';save();render();document.querySelector('#status').textContent='Added.';});
document.querySelector('#search').addEventListener('input',render);
render();Use the preview controls and compare the named behavior checks.
This complete example connects state, form submission, rendering and browser persistence. The source owns a project-specific storage key. On startup it parses saved data inside try/catch and validates required record fields. User actions change records, save the serialized collection and render a view using textContent. A storage failure is reported without pretending the data was saved. The sandbox provides an in-memory localStorage adapter; export the project and serve it over HTTP to verify real reload persistence. Browser storage belongs to an origin and is not a secure vault.
const key = 'discovery-project-19';This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
let records = [];This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
try { const saved=JSON.parse(localStorage.getItem(key)||'[]'); if(Array.isArray(saved))records=saved.filter(x=>typeof x.id==='string'&&typeof x.title==='string'&&typeof x.done==='boolean'); } catch {}Use this project-specific storage key. Parsing, validation and errors are handled separately; the preview uses an in-memory adapter.
function save() { try { localStorage.setItem(key,JSON.stringify(records)); } catch { document.querySelector("#status").textContent="Storage unavailable; current session only."; } }Use this project-specific storage key. Parsing, validation and errors are handled separately; the preview uses an in-memory adapter.
function render() {This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
const list=document.querySelector('#items'); list.replaceChildren();This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
const query=document.querySelector('#search').value.toLowerCase();This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
for(const record of records.filter(x=>x.title.toLowerCase().includes(query))) {This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
const li=document.createElement('li'),toggle=document.createElement('button'),remove=document.createElement('button');This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
toggle.textContent=record.title;toggle.dataset.id=record.id;toggle.setAttribute('aria-pressed',String(record.done));This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
toggle.addEventListener('click',()=>{record.done=!record.done;save();render(); Array.from(document.querySelectorAll('#items button')).find(button => button.dataset.id === record.id)?.focus();});This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
remove.textContent='Remove '+record.title;remove.addEventListener('click',()=>{records=records.filter(x=>x.id!==record.id);save();render(); document.querySelector('#title').focus();});This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
li.append(toggle,remove);list.append(li);This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
}Close the current instruction block.
}Close the current instruction block.
document.querySelector('#form').addEventListener('submit',event=>{event.preventDefault();const field=document.querySelector('#title'),title=field.value.trim();if(!title){document.querySelector('#status').textContent='Enter a task.';return;}records.push({id:crypto.randomUUID(),title,done:false});field.value='';save();render();document.querySelector('#status').textContent='Added.';});Append this value to the existing copy. push mutates the array and returns its new length; the following return sends the array itself.
document.querySelector('#search').addEventListener('input',render);This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
render();This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
const key = 'discovery-project-19';
let records = [];
try { const saved=JSON.parse(localStorage.getItem(key)||'[]'); if(Array.isArray(saved))records=saved.filter(x=>typeof x.id==='string'&&typeof x.title==='string'&&typeof x.done==='boolean'); } catch {}
function save() { try { localStorage.setItem(key,JSON.stringify(records)); } catch { document.querySelector("#status").textContent="Storage unavailable; current session only."; } }
function render() {
const list=document.querySelector('#items'); list.replaceChildren();
const query=document.querySelector('#search').value.toLowerCase();
for(const record of records.filter(x=>x.title.toLowerCase().includes(query))) {
const li=document.createElement('li'),toggle=document.createElement('button'),remove=document.createElement('button');
toggle.textContent=record.title;toggle.dataset.id=record.id;toggle.setAttribute('aria-pressed',String(record.done));
toggle.addEventListener('click',()=>{record.done=!record.done;save();render(); Array.from(document.querySelectorAll('#items button')).find(button => button.dataset.id === record.id)?.focus();});
remove.textContent='Remove '+record.title;remove.addEventListener('click',()=>{records=records.filter(x=>x.id!==record.id);save();render(); document.querySelector('#title').focus();});
li.append(toggle,remove);list.append(li);
}
}
document.querySelector('#form').addEventListener('submit',event=>{event.preventDefault();const field=document.querySelector('#title'),title=field.value.trim();if(!title){document.querySelector('#status').textContent='Enter a task.';return;}records.push({id:crypto.randomUUID(),title,done:false});field.value='';save();render();document.querySelector('#status').textContent='Added.';});
document.querySelector('#search').addEventListener('input',render);
render();
console.log(document.querySelectorAll("li").length);Use the preview controls and compare the named behavior checks.
This complete example connects state, form submission, rendering and browser persistence. The source owns a project-specific storage key. On startup it parses saved data inside try/catch and validates required record fields. User actions change records, save the serialized collection and render a view using textContent. A storage failure is reported without pretending the data was saved. The sandbox provides an in-memory localStorage adapter; export the project and serve it over HTTP to verify real reload persistence. Browser storage belongs to an origin and is not a secure vault.
const key = 'discovery-project-19';This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
let records = [];This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
try { const saved=JSON.parse(localStorage.getItem(key)||'[]'); if(Array.isArray(saved))records=saved.filter(x=>typeof x.id==='string'&&typeof x.title==='string'&&typeof x.done==='boolean'); } catch {}Use this project-specific storage key. Parsing, validation and errors are handled separately; the preview uses an in-memory adapter.
function save() { try { localStorage.setItem(key,JSON.stringify(records)); } catch { document.querySelector("#status").textContent="Storage unavailable; current session only."; } }Use this project-specific storage key. Parsing, validation and errors are handled separately; the preview uses an in-memory adapter.
function render() {This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
const list=document.querySelector('#items'); list.replaceChildren();This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
const query=document.querySelector('#search').value.toLowerCase();This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
for(const record of records.filter(x=>x.title.toLowerCase().includes(query))) {This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
const li=document.createElement('li'),toggle=document.createElement('button'),remove=document.createElement('button');This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
toggle.textContent=record.title;toggle.dataset.id=record.id;toggle.setAttribute('aria-pressed',String(record.done));This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
toggle.addEventListener('click',()=>{record.done=!record.done;save();render(); Array.from(document.querySelectorAll('#items button')).find(button => button.dataset.id === record.id)?.focus();});This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
remove.textContent='Remove '+record.title;remove.addEventListener('click',()=>{records=records.filter(x=>x.id!==record.id);save();render(); document.querySelector('#title').focus();});This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
li.append(toggle,remove);list.append(li);This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
}Close the current instruction block.
}Close the current instruction block.
document.querySelector('#form').addEventListener('submit',event=>{event.preventDefault();const field=document.querySelector('#title'),title=field.value.trim();if(!title){document.querySelector('#status').textContent='Enter a task.';return;}records.push({id:crypto.randomUUID(),title,done:false});field.value='';save();render();document.querySelector('#status').textContent='Added.';});Append this value to the existing copy. push mutates the array and returns its new length; the following return sends the array itself.
document.querySelector('#search').addEventListener('input',render);This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
render();This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
console.log(document.querySelectorAll("li").length);Evaluate the argument and display its value at this point. Quoted text is literal; an unquoted identifier reads its current binding.
const key = 'discovery-project-19';
let records = [];
try { const saved=JSON.parse(localStorage.getItem(key)||'[]'); if(Array.isArray(saved))records=saved.filter(x=>typeof x.id==='string'&&typeof x.title==='string'&&typeof x.done==='boolean'); } catch {}
function save() { try { localStorage.setItem(key,JSON.stringify(records)); } catch { document.querySelector("#status").textContent="Storage unavailable; current session only."; } }
function render() {
const list=document.querySelector('#items'); list.replaceChildren();
const query=document.querySelector('#search').value.toLowerCase();
for(const record of records.filter(x=>x.title.toLowerCase().includes(query))) {
const li=document.createElement('li'),toggle=document.createElement('button'),remove=document.createElement('button');
toggle.textContent=record.title;toggle.dataset.id=record.id;toggle.setAttribute('aria-pressed',String(record.done));
toggle.addEventListener('click',()=>{record.done=!record.done;save();render(); Array.from(document.querySelectorAll('#items button')).find(button => button.dataset.id === record.id)?.focus();});
remove.textContent='Remove '+record.title;remove.addEventListener('click',()=>{records=records.filter(x=>x.id!==record.id);save();render(); document.querySelector('#title').focus();});
li.append(toggle,remove);list.append(li);
}
}
document.querySelector('#form').addEventListener('submit',event=>{event.preventDefault();const field=document.querySelector('#title'),title=field.value.trim();if(!title){document.querySelector('#status').textContent='Enter a task.';return;}records.push({id:crypto.randomUUID(),title,done:false});field.value='';save();render();document.querySelector('#status').textContent='Added.';});
document.querySelector('#search').addEventListener('input',render);
render();
console.log(document.querySelectorAll("button").length);Use the preview controls and compare the named behavior checks.
This complete example connects state, form submission, rendering and browser persistence. The source owns a project-specific storage key. On startup it parses saved data inside try/catch and validates required record fields. User actions change records, save the serialized collection and render a view using textContent. A storage failure is reported without pretending the data was saved. The sandbox provides an in-memory localStorage adapter; export the project and serve it over HTTP to verify real reload persistence. Browser storage belongs to an origin and is not a secure vault.
const key = 'discovery-project-19';This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
let records = [];This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
try { const saved=JSON.parse(localStorage.getItem(key)||'[]'); if(Array.isArray(saved))records=saved.filter(x=>typeof x.id==='string'&&typeof x.title==='string'&&typeof x.done==='boolean'); } catch {}Use this project-specific storage key. Parsing, validation and errors are handled separately; the preview uses an in-memory adapter.
function save() { try { localStorage.setItem(key,JSON.stringify(records)); } catch { document.querySelector("#status").textContent="Storage unavailable; current session only."; } }Use this project-specific storage key. Parsing, validation and errors are handled separately; the preview uses an in-memory adapter.
function render() {This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
const list=document.querySelector('#items'); list.replaceChildren();This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
const query=document.querySelector('#search').value.toLowerCase();This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
for(const record of records.filter(x=>x.title.toLowerCase().includes(query))) {This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
const li=document.createElement('li'),toggle=document.createElement('button'),remove=document.createElement('button');This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
toggle.textContent=record.title;toggle.dataset.id=record.id;toggle.setAttribute('aria-pressed',String(record.done));This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
toggle.addEventListener('click',()=>{record.done=!record.done;save();render(); Array.from(document.querySelectorAll('#items button')).find(button => button.dataset.id === record.id)?.focus();});This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
remove.textContent='Remove '+record.title;remove.addEventListener('click',()=>{records=records.filter(x=>x.id!==record.id);save();render(); document.querySelector('#title').focus();});This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
li.append(toggle,remove);list.append(li);This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
}Close the current instruction block.
}Close the current instruction block.
document.querySelector('#form').addEventListener('submit',event=>{event.preventDefault();const field=document.querySelector('#title'),title=field.value.trim();if(!title){document.querySelector('#status').textContent='Enter a task.';return;}records.push({id:crypto.randomUUID(),title,done:false});field.value='';save();render();document.querySelector('#status').textContent='Added.';});Append this value to the existing copy. push mutates the array and returns its new length; the following return sends the array itself.
document.querySelector('#search').addEventListener('input',render);This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
render();This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
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.
Build an add/delete task flow, reject blank input, render titles as text and clear the input on success.
const key = 'discovery-project-19';
let records = [];
try { const saved=JSON.parse(localStorage.getItem(key)||'[]'); if(Array.isArray(saved))records=saved.filter(x=>typeof x.id==='string'&&typeof x.title==='string'&&typeof x.done==='boolean'); } catch {}
function save() { try { localStorage.setItem(key,JSON.stringify(records)); } catch { document.querySelector("#status").textContent="Storage unavailable; current session only."; } }
function render() {
const list=document.querySelector('#items'); list.replaceChildren();
const query=document.querySelector('#search').value.toLowerCase();
for(const record of records.filter(x=>x.title.toLowerCase().includes(query))) {
const li=document.createElement('li'),toggle=document.createElement('button'),remove=document.createElement('button');
toggle.textContent=record.title;toggle.dataset.id=record.id;toggle.setAttribute('aria-pressed',String(record.done));
toggle.addEventListener('click',()=>{record.done=!record.done;save();// Add the last initialization or handler here.});
remove.textContent='Remove '+record.title;remove.addEventListener('click',()=>{records=records.filter(x=>x.id!==record.id);save();render(); Array.from(document.querySelectorAll('#items button')).find(button => button.dataset.id === record.id)?.focus();});
li.append(toggle,remove);list.append(li);
}
}
document.querySelector('#form').addEventListener('submit',event=>{event.preventDefault();const field=document.querySelector('#title'),title=field.value.trim();if(!title){document.querySelector('#status').textContent='Enter a task.';return;}records.push({id:crypto.randomUUID(),title,done:false});field.value='';save();render();document.querySelector('#status').textContent='Added.';});
document.querySelector('#search').addEventListener('input',render);
render();const key = 'discovery-project-19';
let records = [];
try { const saved=JSON.parse(localStorage.getItem(key)||'[]'); if(Array.isArray(saved))records=saved.filter(x=>typeof x.id==='string'&&typeof x.title==='string'&&typeof x.done==='boolean'); } catch {}
function save() { try { localStorage.setItem(key,JSON.stringify(records)); } catch { document.querySelector("#status").textContent="Storage unavailable; current session only."; } }
function render() {
const list=document.querySelector('#items'); list.replaceChildren();
const query=document.querySelector('#search').value.toLowerCase();
for(const record of records.filter(x=>x.title.toLowerCase().includes(query))) {
const li=document.createElement('li'),toggle=document.createElement('button'),remove=document.createElement('button');
toggle.textContent=record.title;toggle.dataset.id=record.id;toggle.setAttribute('aria-pressed',String(record.done));
toggle.addEventListener('click',()=>{record.done=!record.done;save();render(); Array.from(document.querySelectorAll('#items button')).find(button => button.dataset.id === record.id)?.focus();});
remove.textContent='Remove '+record.title;remove.addEventListener('click',()=>{records=records.filter(x=>x.id!==record.id);save();render(); document.querySelector('#title').focus();});
li.append(toggle,remove);list.append(li);
}
}
document.querySelector('#form').addEventListener('submit',event=>{event.preventDefault();const field=document.querySelector('#title'),title=field.value.trim();if(!title){document.querySelector('#status').textContent='Enter a task.';return;}records.push({id:crypto.randomUUID(),title,done:false});field.value='';save();render();document.querySelector('#status').textContent='Added.';});
document.querySelector('#search').addEventListener('input',render);
render();Create separate label and button nodes instead of an HTML string.
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.