0

Using javascript and html together in sololearn

Heyy I've this doubt, if you can please help. When I write document.getElementById() inside a script tag in the html file, I'm getting the desired output, but when I write the same in javascript file, I'm not getting the output , how do I link the Js file to html file in sololearn code playground ? Like there's no specific name to the Js file, which I can write inside href of a script tag, so how do I do it on sololearn playground? Help

27th May 2019, 6:18 PM
Prakhar Parashar
Prakhar Parashar - avatar
3 Respostas
+ 1
on JS code playground add onload = function() { document.getElementById('content').innerHTML='Hello'; };
7th Dec 2020, 9:40 PM
wawan sismadi
wawan sismadi - avatar
0
JavaScript, HTML and CSS are automaticaly linked within the sololearn's code playground. Maybe your problem is elsewhere. Also, remember that you should use the 'src' attribute for scripts, not 'href'
27th May 2019, 6:28 PM
Andres0b0100
Andres0b0100 - avatar
0
Made a simple version of "Minecraft" in my spare time if you want to try it go ahead <!DOCTYPE html> <html> <head> <title>Minecraft-like Game</title> <style> canvas { border: 1px solid black; } </style> </head> <body> <canvas id="canvas" width="800" height="600"></canvas> <script> // Define world size and block size const WORLD_WIDTH = 20; const WORLD_HEIGHT = 15; const BLOCK_SIZE = 40; // Define block types const BLOCK_TYPES = { 0: { name: 'air', color: '#FFFFFF' }, 1: { name: 'dirt', color: '#8B4513' }, 2: { name: 'grass', color: '#00FF00' }, 3: { name: 'stone', color: '#A9A9A9' } }; // Initialize world array const world = []; for (let i = 0; i < WORLD_HEIGHT; i++) { world[i] = []; for (let j = 0; j < WORLD_WIDTH; j++) { world[i][j] = Math.floor(Math.random() * 4); } } // Get canvas context const canvas = document.getElementById('canvas'); const ctx = canvas.getContext('2d'); // Draw the w
5th May 2023, 3:15 AM
But Hole
But Hole - avatar