{ "$schema": "../schemas/code-crispies-module-schema.json", "id": "js-variables", "title": "JS Variables", "description": "Learn to declare variables with let and const, and work with basic data types in JavaScript.", "mode": "javascript", "difficulty": "beginner", "lessons": [ { "id": "js-const", "title": "Constants", "description": "Use const to declare a variable that cannot be reassigned. Constants are the default choice for most values in modern JavaScript.", "task": "Declare a constant named name with the value \"Alice\"", "previewHTML": "

Waiting...

", "previewBaseCSS": "body { font-family: system-ui, sans-serif; padding: 1rem; }", "sandboxCSS": "", "initialCode": "", "codePrefix": "", "codeSuffix": "\ndocument.getElementById('out').textContent = name;", "solution": "const name = \"Alice\";", "previewContainer": "preview-area", "validations": [ { "type": "contains", "value": "const", "message": "Use const to declare the variable" }, { "type": "regex", "value": "const\\s+name\\s*=", "message": "Declare a constant called name" }, { "type": "regex", "value": "\"Alice\"|'Alice'|`Alice`", "message": "Set the value to \"Alice\"" } ] }, { "id": "js-let", "title": "Let Variables", "description": "Use let to declare variables that you plan to reassign later. Unlike const, a let variable can change its value.", "task": "Declare a variable count with let set to 0, then reassign it to 5", "previewHTML": "

Waiting...

", "previewBaseCSS": "body { font-family: system-ui, sans-serif; padding: 1rem; }", "sandboxCSS": "", "initialCode": "", "codePrefix": "", "codeSuffix": "\ndocument.getElementById('out').textContent = count;", "solution": "let count = 0;\ncount = 5;", "previewContainer": "preview-area", "validations": [ { "type": "regex", "value": "let\\s+count\\s*=\\s*0", "message": "Start with let count = 0;" }, { "type": "regex", "value": "count\\s*=\\s*5", "message": "Reassign count to 5" } ] }, { "id": "js-string", "title": "Template Literals", "description": "Template literals use backticks ` and ${} to embed expressions inside strings. This makes building dynamic text much easier than string concatenation.", "task": "Create a constant msg using a template literal: `Hello, ${name}!`", "previewHTML": "

Waiting...

", "previewBaseCSS": "body { font-family: system-ui, sans-serif; padding: 1rem; }", "sandboxCSS": "", "initialCode": "", "codePrefix": "const name = \"World\";\n", "codeSuffix": "\ndocument.getElementById('out').textContent = msg;", "solution": "const msg = `Hello, ${name}!`;", "previewContainer": "preview-area", "validations": [ { "type": "regex", "value": "const\\s+msg\\s*=", "message": "Declare a constant called msg" }, { "type": "contains", "value": "${name}", "message": "Use ${name} inside backticks to embed the variable" }, { "type": "regex", "value": "`.*\\$\\{name\\}.*`", "message": "Wrap the whole string in backticks `" } ] }, { "id": "js-array", "title": "Arrays", "description": "Arrays store ordered lists of values in square brackets. Access items by index (starting at 0) and use .length to get the count.", "task": "Create a constant colors with an array: [\"red\", \"green\", \"blue\"]", "previewHTML": "

Waiting...

", "previewBaseCSS": "body { font-family: system-ui, sans-serif; padding: 1rem; }", "sandboxCSS": "", "initialCode": "", "codePrefix": "", "codeSuffix": "\ndocument.getElementById('out').textContent = colors.join(', ');", "solution": "const colors = [\"red\", \"green\", \"blue\"];", "previewContainer": "preview-area", "validations": [ { "type": "regex", "value": "const\\s+colors\\s*=", "message": "Declare a constant called colors" }, { "type": "contains", "value": "[", "message": "Use square brackets [ to create an array" }, { "type": "regex", "value": "(\"red\"|'red'|`red`)", "message": "Include \"red\" in the array" }, { "type": "regex", "value": "(\"green\"|'green'|`green`)", "message": "Include \"green\" in the array" }, { "type": "regex", "value": "(\"blue\"|'blue'|`blue`)", "message": "Include \"blue\" in the array" } ] } ] }