3 ms·
Not short but almost understandable. Given a text editor, save the following text as drawline.html: <canvas id="myCanvas" width="500" height="300"></canvas>
by theoa 2y ago
Not short but almost understandable. Given a text editor, save the following text as drawline.html:
<canvas id="myCanvas" width="500" height="300"></canvas>
<script>
const ctx = myCanvas.getContext( "2d" );
// Draw the line
ctx.beginPath();
ctx.moveTo( 50, 50 ); // Starting point
ctx.lineTo( 200, 150 ); // Ending point
ctx.stroke();
document.write( "Hello World" );
</script>
JavaScript is quite forgiving. No need for the HTML preambles. "document.getElementById" is a nicety that can also be ignored.
Nonetheless, I (born 1947) too miss the simplicity of BASIC, the plethora of magazines for beginners, the many shelves of "for dummies books". And, especially, that we were all beginners.
These days, full stack developers and AI are priestly classes that that, currently, do not facilitate the investigation by newbs of the black boxes they create.
Nonetheless, I look forward to AI being able to read aloud Python, Rust, Cobal, Euler notation, Greek or whatever in ways that I may understand.
- ben_w 2y ago> "document.getElementById" is a nicety that can also be ignored. Huh, I did not know that. This makes it a lot nicer for micro-projects.
- vekatimest 2y agoI had no idea named elements just become globals like that. Seems kind of ridiculous
- blacksmith_tb 2y agoid-s do, which is handy here, but sometimes exciting if you aren't expecting it.
- theoa 2y agoI discovered this perhaps ten or more years ago. I have used IDs a global in hundreds (thousand?) of efforts with no issues. Ever. Of course, I am but a single stack developer, so your experience may vary