{ "$schema": "../schemas/code-crispies-module-schema.json", "id": "js-variables", "title": "JS Variables", "description": "Learn to declare variables with let and const, work with strings and numbers, and use template literals to build dynamic text.", "mode": "javascript", "difficulty": "beginner", "lessons": [ { "id": "js-const", "title": "Constants", "description": "Use const to declare a variable that cannot be reassigned. Constants are great for values that stay the same throughout your program.", "task": "Declare a constant named name with the value \"Ada\"", "previewHTML": "
Waiting...
", "previewBaseCSS": "body { font-family: system-ui, sans-serif; padding: 1rem; }", "sandboxCSS": "", "initialCode": "", "solution": "const name = \"Ada\";", "codePrefix": "", "codeSuffix": "\ndocument.getElementById(\"out\").textContent = name;", "previewContainer": "preview-area", "validations": [ { "type": "contains", "value": "const", "message": "Use const to declare the variable" }, { "type": "regex", "value": "const\\s+name\\s*=", "message": "Name your constant name" }, { "type": "regex", "value": "[\"']Ada[\"']", "message": "Set the value to \"Ada\"" } ] }, { "id": "js-let", "title": "Let Variables", "description": "Use let to declare a variable that can be reassigned later. This is useful when you need to update a value.", "task": "Declare a variable score with let and set it to 0", "previewHTML": "Waiting...
", "previewBaseCSS": "body { font-family: system-ui, sans-serif; padding: 1rem; }", "sandboxCSS": "", "initialCode": "", "solution": "let score = 0;", "codePrefix": "", "codeSuffix": "\ndocument.getElementById(\"out\").textContent = \"Score: \" + score;", "previewContainer": "preview-area", "validations": [ { "type": "contains", "value": "let", "message": "Use let to declare the variable" }, { "type": "regex", "value": "let\\s+score\\s*=\\s*0", "message": "Set score to 0" } ] }, { "id": "js-template", "title": "Template Literals", "description": "Template literals use backticks ` and ${} to embed expressions inside strings. They make building dynamic text much easier than string concatenation.", "task": "Create a const msg using a template literal: `Hi, ${name}!`", "previewHTML": "Waiting...
", "previewBaseCSS": "body { font-family: system-ui, sans-serif; padding: 1rem; }", "sandboxCSS": "", "initialCode": "", "solution": "const msg = `Hi, ${name}!`;", "codePrefix": "const name = \"Ada\";\n", "codeSuffix": "\ndocument.getElementById(\"out\").textContent = msg;", "previewContainer": "preview-area", "validations": [ { "type": "contains", "value": "${", "message": "Use ${} to embed the variable inside the template" }, { "type": "regex", "value": "`[^`]*\\$\\{\\s*name\\s*\\}[^`]*`", "message": "Embed name inside a template literal with backticks" }, { "type": "regex", "value": "const\\s+msg\\s*=", "message": "Assign the result to a constant named msg" } ] } ] }