+ 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
16 Respuestas
+ 3
It's now showing a reference error because variable c is used outside it's scope.Declare it as a global var.
+ 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
+ 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.
+ 4
Shantanu Sikder it isn't showing any error for me, on which line do you get an error?
+ 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.
+ 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.
+ 2
and yes, I don't think that it would actually make any difference because I have declared them globally using var.
+ 2
It's not global yet it's inside a function declare it at the very top free of any scope.
+ 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
+ 1
Could there be any reserved word error?
+ 1
I'll see. Thanks Ajax
+ 1
Yash Kandalkar your code too is showing up an 'Unreserved word...' error
+ 1
Please run my code again... It is still showing an error
0
Sorry Ajax , but it isn't making it work.
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"!!