Web

Interactive Code Playground Examples

Learn how to use the interactive code features

K

Kambrathi

Author

January 16, 2024

Published

8 min read

Read time

Interactive Code Playground Examples

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

JavaScript
โœ“ Auto-saved
๐Ÿ’ก Tip: Press Ctrl+Enter to run codeLines: 10 | Characters: 187

Features 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

JavaScript
๐Ÿ’ก Tip: Press Ctrl+Enter to run codeLines: 21 | Characters: 550

3. CodeSandbox - Full Project Environment

For more complex projects, we can embed full CodeSandbox environments:

React Starter Template

CodeSandbox
Open in CodeSandbox
๐Ÿ’ก Edit the code directly in the sandbox

This 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

EASY

Print numbers 1-100. For multiples of 3 print 'Fizz', for multiples of 5 print 'Buzz', for multiples of both print 'FizzBuzz'

๐Ÿ’ก Write a function that passes all test cases2 test cases

Challenge 2: Palindrome Checker (Medium)

Palindrome Checker

MEDIUM

Determine if a given string is a palindrome (reads same forwards and backwards)

๐Ÿ’ก Write a function that passes all test cases3 test cases

Challenge 3: Find Duplicates (Hard)

Find Duplicates

HARD

Find all duplicate values in an array. Return an array of unique duplicates.

๐Ÿ’ก Write a function that passes all test cases3 test cases

5. TypeScript Support

You can also use TypeScript in the playground:

TypeScript Example

TypeScript
๐Ÿ’ก Tip: Press Ctrl+Enter to run codeLines: 17 | Characters: 392

6. Read-Only Demo

Sometimes you want to show code without allowing edits:

Fibonacci Sequence (Demo)

JavaScript
๐Ÿ’ก Tip: Press Ctrl+Enter to run codeLines: 10 | Characters: 248

Tips for Using Code Components

1. CodePlayground

  • โœ… Best for: Quick JavaScript/TypeScript examples
  • โœ… Use: Interactive tutorials, demos
  • โœ… Auto-save: Add saveKey for 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

  1. Try solving all three challenges above
  2. Experiment with the playgrounds
  3. Create your own code examples
  4. Share your solutions!

Happy coding! ๐Ÿš€

K

Kambrathi

Published on January 16, 2024