+ 4

Why is my code showing an "Uncaught Syntax error" at Line-12? Also please correct my code wherever there is a mistake. Thanks.

I'm trying to draw a rectangular 'paddle' on the canvas at the bottom (see the code for dimensions and positions) but everytime I run it I get an 'Uncaught Syntax error' at Line-12 and I'm also not sure about the overall correctness of the code. Please help. https://code.sololearn.com/Wt02Qlbg178K/?ref=app

30th Oct 2018, 1:07 AM
SSki11
SSki11 - avatar
16 Answers
+ 3
It's now showing a reference error because variable c is used outside it's scope.Declare it as a global var.
30th Oct 2018, 3:58 AM
Ajax
Ajax - avatar
+ 5
Shantanu Sikder functions on classes aren't defined that way in JavaScript, you do class A{ constructor(){} drawIt(){ } } You don't write "function" there Here's a fixed code, i had to make other changes too which you can compare https://code.sololearn.com/W57JRUelGZ3g/?ref=app
31st Oct 2018, 3:27 AM
Yash✳️
Yash✳️ - avatar
+ 5
Shantanu Sikder you need to define canvas and the context variable (c) in the window.onload function. Just as i did in the code i sent above, in my first reply.
31st Oct 2018, 10:30 AM
Yash✳️
Yash✳️ - avatar
+ 4
Shantanu Sikder it isn't showing any error for me, on which line do you get an error?
31st Oct 2018, 10:28 AM
Yash✳️
Yash✳️ - avatar
+ 2
Coder Thanks, but I have already created mine on my PC and it is working well there. I'll see the correction you suggested.
31st Oct 2018, 10:25 AM
SSki11
SSki11 - avatar
+ 2
Yash Kandalkar Thanks again, but you may see the code again... there's still an unexpected error (in the declaration line of 'paddleGame' class block.
31st Oct 2018, 11:01 AM
SSki11
SSki11 - avatar
+ 2
and yes, I don't think that it would actually make any difference because I have declared them globally using var.
31st Oct 2018, 11:01 AM
SSki11
SSki11 - avatar
+ 2
It's not global yet it's inside a function declare it at the very top free of any scope.
31st Oct 2018, 11:07 AM
Ajax
Ajax - avatar
+ 2
YES, IT WORKS WELL NOW! Thanks Ajax, Yash Kandalkar , Coder for helping me. This one works well... check it out! https://code.sololearn.com/Wt02Qlbg178K/?ref=app
31st Oct 2018, 11:59 PM
SSki11
SSki11 - avatar
+ 1
Could there be any reserved word error?
30th Oct 2018, 1:08 AM
SSki11
SSki11 - avatar
+ 1
I'll see. Thanks Ajax
30th Oct 2018, 10:11 AM
SSki11
SSki11 - avatar
+ 1
Yash Kandalkar your code too is showing up an 'Unreserved word...' error
31st Oct 2018, 10:27 AM
SSki11
SSki11 - avatar
+ 1
Please run my code again... It is still showing an error
31st Oct 2018, 10:28 AM
SSki11
SSki11 - avatar
0
Sorry Ajax , but it isn't making it work.
30th Oct 2018, 1:58 PM
SSki11
SSki11 - avatar
0
What I've found is THIS CODE RUNS PRETTY GOOD IN MY PC (USING 'OPERA' OR 'CHROME') BUT "SOLOLEARN INTERPRETER ISN'T ABLE TO DO THAT"!!
31st Oct 2018, 12:59 AM
SSki11
SSki11 - avatar