0

This is JavaScript code is not running on sololearn....can anyone tell why??

"use strict"; { const txt = 'STRINGS'; const viscosity = 0.005; const stiffness = 0.99; class Point { constructor (i, x, y) { this.c = null; this.x0 = x; this.y0 = y; this.x = x + Math.sin(i) * 100; this.y = y + Math.cos(i) * 100; this.vx = 0.0; this.vy = 0.0; this.a = 0.0; this.s = 0.0; this.p0 = this; this.p1 = this; this.t = 0; } texture (c, color) { this.c = document.createElement("canvas"); const ctx = this.c.getContext("2d"); this.c.width = this.c.height = 400; ctx.font = "500px Arial Black, Arial"; ctx.fillStyle = color;

7th Feb 2021, 8:57 AM
Utkarsh
Utkarsh - avatar
6 Answers
+ 1
Utkarsh Bansal place your javascript code inside the following function onload=()=>{ } the above function will only run when html document if fully loaded unlike what is happening in your case is that javascript is getting executed before dom loading ,which means the element body doesn't exist yet. And this is happening since sololearn puts js file inside head tag.
7th Feb 2021, 9:16 AM
Abhay
Abhay - avatar
+ 1
Yeah.... it's working fine now....thank you
7th Feb 2021, 9:19 AM
Utkarsh
Utkarsh - avatar
0
Did you appended canvas to body element of document?
7th Feb 2021, 9:00 AM
Abhay
Abhay - avatar
0
Yes I did
7th Feb 2021, 9:03 AM
Utkarsh
Utkarsh - avatar
0
7th Feb 2021, 9:11 AM
Utkarsh
Utkarsh - avatar
0
Of the question asked above
7th Feb 2021, 9:12 AM
Utkarsh
Utkarsh - avatar