`, // CSS snippet `body { background-color: #f0f0f0; color: #333; } .container { display: flex; justify-content: center; }`, // C snippet `#include int main() { printf("Hello, C World!\\n"); return 0; }`, // Java snippet `public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, Java World!"); } }`, // SQL snippet `SELECT * FROM users WHERE active = 1; UPDATE products SET price = price * 1.1 WHERE category = 'Electronics';`, // Bash snippet `#!/bin/bash echo "Hello, Bash!"`, // JSON snippet `{ "name": "John Doe", "age": 30, "city": "New York" }`, // Ruby snippet `puts "Hello from Ruby!" array = [1, 2, 3, 4, 5] array.each { |num| puts num }`, // Swift snippet `import Foundation print("Hello, Swift!")`, // Miscellaneous comments and code fragments `// TODO: Refactor this code /* Multi-line comment: This is a CSS or C-style comment */ # This is a shell comment` ]; // Variables to track the current snippet and position let currentSnippet = null; let currentIndex = 0; /** * Picks a new random snippet from sampleCodeSnippets and resets the index. */ function pickNewSnippet() { currentSnippet = sampleCodeSnippets[Math.floor(Math.random() * sampleCodeSnippets.length)]; currentIndex = 0; } /** * Appends the next character from the current snippet to rawText. * If the current snippet is finished, adds a newline and resets for the next snippet. */ function addNextCharacter() { // If there's no snippet selected or it was finished, pick a new snippet. if (!currentSnippet) { pickNewSnippet(); } // Append the next character if available. if (currentIndex < currentSnippet.length) { rawText += currentSnippet[currentIndex]; currentIndex++; } // If we've reached the end of the snippet, add a newline and reset. if (currentIndex >= currentSnippet.length) { rawText += "\n"; currentSnippet = null; } // Update the code area: set textContent to rawText then re-highlight. codeArea.textContent = rawText; hljs.highlightElement(codeArea); // Auto-scroll to the bottom. window.scrollTo(0, document.body.scrollHeight); } // Listen for any keydown event and add the next character. document.addEventListener('keydown', addNextCharacter);