Interactive Code Playground Examples
Welcome to the interactive code playground! This post demonstrates all three types of code components available in your lessons.
1. CodePlayground - Try It Live!
Edit and run JavaScript code directly in your browser:
JavaScript Playground
JavaScriptFeatures You Can Try:
- Edit the code above
- Click โRun Codeโ to see output
- Use โShareโ to create a shareable link
- โDownloadโ to save your code
- Your changes auto-save!
2. Advanced Example - Array Manipulation
Array Operations
JavaScript3. CodeSandbox - Full Project Environment
For more complex projects, we can embed full CodeSandbox environments:
React Starter Template
CodeSandboxThis embedded sandbox includes:
- โ Full React environment
- โ NPM package installation
- โ Multiple files
- โ Live preview
- โ Hot module reloading
4. Code Challenges - Test Your Skills!
Challenge 1: FizzBuzz (Easy)
FizzBuzz
Print numbers 1-100. For multiples of 3 print 'Fizz', for multiples of 5 print 'Buzz', for multiples of both print 'FizzBuzz'
Challenge 2: Palindrome Checker (Medium)
Palindrome Checker
Determine if a given string is a palindrome (reads same forwards and backwards)
Challenge 3: Find Duplicates (Hard)
Find Duplicates
Find all duplicate values in an array. Return an array of unique duplicates.
5. TypeScript Support
You can also use TypeScript in the playground:
TypeScript Example
TypeScript6. Read-Only Demo
Sometimes you want to show code without allowing edits:
Fibonacci Sequence (Demo)
JavaScriptTips for Using Code Components
1. CodePlayground
- โ Best for: Quick JavaScript/TypeScript examples
- โ Use: Interactive tutorials, demos
- โ
Auto-save: Add
saveKeyfor important exercises
2. CodeSandbox
- โ Best for: Full projects, React/Vue apps
- โ Use: Complex examples with dependencies
- โ Create: Projects at codesandbox.io or stackblitz.com
3. CodeChallenge
- โ Best for: Practice problems, assessments
- โ Use: End-of-lesson exercises
- โ Include: Clear test cases and hints
Next Steps
- Try solving all three challenges above
- Experiment with the playgrounds
- Create your own code examples
- Share your solutions!
Happy coding! ๐
Kambrathi
Published on January 16, 2024