JavaScript: Draw a diagram using moveto() function
JavaScript Drawing: Exercise-5 with Solution
MoveTo Diagram
Write a JavaScript program to draw the following diagram [use the moveto() function].
Sample output:

Sample Solution:
HTML Code:
JavaScript Code:
Live Demo:
For more Practice: Solve these Related Problems:
- Write a JavaScript program that uses moveTo() and lineTo() to draw a star shape with multiple points.
- Write a JavaScript program that draws a simple house diagram (with a roof, door, and windows) using moveTo() and lineTo().
- Write a JavaScript program that creates a zigzag pattern across the canvas using moveTo() for starting each line segment.
- Write a JavaScript program that draws a regular polygon (e.g., hexagon) by calculating vertices and connecting them with moveTo() and lineTo().
Improve this sample solution and post your code through Disqus.
Previous: Write a JavaScript program to draw the following right-angled triangle.
Next: Write a JavaScript program to draw the following diagram [diagonal, white to black circles].
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.