JavaScript drawing - Exercises, Practice, Solution
JavaScript drawing [6 exercises with solution]
[An editor is available at the bottom of the page to write and execute the scripts.]
1. Write a JavaScript program to draw the following rectangular shape. Go to the editor
Expected Output :
Click me to see the solution
2. Write a JavaScript program to draw a circle. Go to the editor
Expected Output :
Click me to see the solution
3. Write a JavaScript program to draw two intersecting rectangles, one of which has alpha transparency. Go to the editor
Expected Output :
Click me to see the solution
4. Write a JavaScript program to draw the following right-angled triangle. Go to the editor
Expected Output :
Click me to see the solution
5. Write a JavaScript program to draw the following diagram [use moveto() function]. Go to the editor
Expected Output :
Click me to see the solution
6. Write a JavaScript program to draw the following diagram [diagonal, white to black circles]. Go to the editor
Expected Output :
Click me to see the solution
More to Come !
* To run the code mouse over on Result panel and click on 'RERUN' button.*
Live Demo:
See the Pen javascript-common-editor by w3resource (@w3resource) on CodePen.
Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.
JavaScript: Tips of the Day
How to insert an item into an array at a specific index (JavaScript)?
What you want is the splice function on the native array object.
arr.splice(index, 0, item); will insert item into arr at the specified index (deleting 0 items first, that is, it's just an insert). In this example we will create an array and add an element to it into index 2:
var arr = []; arr[0] = "Jani"; arr[1] = "Hege"; arr[2] = "Stale"; arr[3] = "Kai Jim"; arr[4] = "Borge"; console.log(arr.join()); arr.splice(2, 0, "Lene"); console.log(arr.join());
Ref: https://bit.ly/2BXbp04
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework