+ 1

how we resolve the problem

solo learn editor give the error that you dont use the null in getContext while other compiler execute the code and also give the output const cany=document.getElementById('cani'); const v=cany.getContext('2d'); v.beginPath(); v.fillStyle="green"; v.fillRect(12,5,440,550); v.clearRect(102,42,127,75) v.beginPath(); v.fillStyle="purple"; v.moveTo(18,5); v.lineTo(102,80); v.lineTo(19,140); v.fill(); v.clearRect(222,42,139,23)

15th Mar 2020, 8:14 AM
Mohammad Waqas
Mohammad Waqas - avatar
4 ответов
+ 8
//You code is working , put all your code inside html inside of js section https://code.sololearn.com/W6Fl7Ot8mbxu/?ref=app
15th Mar 2020, 8:18 AM
Sudarshan Rai
Sudarshan Rai - avatar
+ 2
The reason behind it, the section where you write the JS code loads before the DOM rendered, for dealing with this, write your code inside a script element before the closing element of body or write your code inside the window.onload function like this window.onload=function(){ //code }
15th Mar 2020, 10:31 AM
Farhan
Farhan - avatar
+ 1
Ok thanks i will try
15th Mar 2020, 8:36 AM
Mohammad Waqas
Mohammad Waqas - avatar
+ 1
Thanks that is executing
15th Mar 2020, 8:38 AM
Mohammad Waqas
Mohammad Waqas - avatar