Code Playground
Home
About
Games
AI Chat
Settings
Code Playground
Logout
Code Playground
Select Language:
Python
JavaScript
HTML
C++
Java
File Name:
Add File
Run Code
Output:
`; }).join('\n'); const iframe = document.getElementById('outputIframe'); iframe.srcdoc = htmlContent; showOutput('html'); return; } try { const response = await fetch('https://judge0.p.rapidapi.com/submissions?base64_encoded=false&wait=true', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-RapidAPI-Key': 'YOUR_RAPIDAPI_KEY', 'X-RapidAPI-Host': 'judge0.p.rapidapi.com' }, body: JSON.stringify({ source_code: fileEntries.map(([fileName, content]) => `# ${fileName}\n${content}`).join('\n\n'), language_id: getLanguageId(language) }) }); const data = await response.json(); document.getElementById('outputText').textContent = data.stdout || data.stderr || 'Error running code'; showOutput('text'); } catch (error) { console.error('Error:', error); document.getElementById('outputText').textContent = 'Error running code'; showOutput('text'); } }); function showOutput(type) { document.getElementById('outputText').style.display = type === 'text' ? 'block' : 'none'; document.getElementById('outputImage').style.display = type === 'image' ? 'block' : 'none'; document.getElementById('outputIframe').style.display = type === 'html' ? 'block' : 'none'; } function getLanguageId(language) { switch (language) { case 'python': return 71; // Python 3 case 'javascript': return 63; // JavaScript case 'html': return null; // HTML handled separately case 'cpp': return 54; // C++ case 'java': return 62; // Java // Add more languages and their corresponding IDs default: return 71; // Default to Python 3 } } });