+ 30

Why is JavaScript in different learning apps different from each other?

I've learned js in Khanacademy for three years. When I came here, the basics are same, but some stuff are absolutely different. I'm really upset thinking that I've wasted my time... For example: in Khanacademy, fill(0, 255, 0); rect(200, 200, 20, 20); Drew a green rectangle. But in Sololearn code playground, it says rect and fill undefined...and many other problems. Am I unable to understand, or the types of js are different? Which one of them is right?

24th May 2019, 8:00 AM
Humayra🇧🇩
Humayra🇧🇩 - avatar
6 Answers
+ 10
Humayra_Islam:)🇧🇩 Hi don't be upset Js is same everywhere there no such thing like different js. I bet sololearn is giving error because u need to wrap the code in: window.onload this is happening because the script must be executing before your DOM is read. //Also please share your code in the question so that we can see what u are doing wrong Like: window.onload = function() { //Ur code here }; - - - - - -Based on your question- - - - - window.onload = function(){ const canvas = document.getElementById('canvas'); const ctx = canvas.getContext('2d'); ctx.rect(10, 20, 150, 100); ctx.fillStyle = "Green"; ctx.fill(); } - - - - - - - - - - - - - - - - - - - - - - - - - - - - //See i have created a green rectangle for u: https://code.sololearn.com/W9ATlimn5o0B/?ref=app
24th May 2019, 8:32 AM
Sick L̲̅i̲̅n̲̅e̲̅🌡️[TheBraveCoders]
Sick L̲̅i̲̅n̲̅e̲̅🌡️[TheBraveCoders] - avatar
+ 23
Thanks, it helped🙂🙂
24th May 2019, 8:55 AM
Humayra🇧🇩
Humayra🇧🇩 - avatar
+ 23
Well, that's it... In Khanacademy, they didn't need a draw function... Thanks, Arb Rahim Badsa for the help 🙂🙂
24th May 2019, 5:38 PM
Humayra🇧🇩
Humayra🇧🇩 - avatar
+ 8
Cbr✔ No All programming languages has their own House to stay! Means Every languages has their different path and syntaxs too!...
26th May 2019, 1:51 PM
Rishabh Singh
Rishabh Singh - avatar
+ 7
JS is same everywhere! I can guess you might have learnt their the p5.js library! As you said, fill(0, 255, 0); rect(200,200,20,20); Will create a green rectangle if you put them inside draw function! Just like this one : https://code.sololearn.com/W2XXFPbT3WS4/?ref=app
24th May 2019, 5:17 PM
Arb Rahim Badsa
Arb Rahim Badsa - avatar
+ 3
Humayra_Islam:)🇧🇩 You are welcome, Enjoy! 👍😄😆
24th May 2019, 9:06 AM
Sick L̲̅i̲̅n̲̅e̲̅🌡️[TheBraveCoders]
Sick L̲̅i̲̅n̲̅e̲̅🌡️[TheBraveCoders] - avatar