Why I get error? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why I get error?

This code is not working: var c, var w = c.width = window.innerWidth, h = c.height = window.innerHeight;

16th Apr 2018, 5:54 AM
Andrey Nazarov
Andrey Nazarov - avatar
7 Answers
+ 6
Because the declaration for c is ambiguous unless you specify it explicitly as an object with the corresponding attribute like following:- var c = { width: null, height: null }; Anyway it's still a little bit strange to me to have more than one assignment in a single statement although it's working fine.
16th Apr 2018, 6:16 AM
Zephyr Koo
Zephyr Koo - avatar
+ 5
Андрей Назаров sorry but that is wrong,if you say c=document.querySelector("canvas"); c already automatically has width and height properties so by saying c={width:null,height:null} youre changing c value completely making line1 useless.We all make mistakes,youll have to choose between both
16th Apr 2018, 6:37 AM
᠌᠌Brains[Abidemi]
᠌᠌Brains[Abidemi] - avatar
+ 4
ive seen your code,after 5 minutes of adjustment,ive repaired it: https://code.sololearn.com/WF1E2fJ9CWbn/?ref=app
16th Apr 2018, 6:42 AM
᠌᠌Brains[Abidemi]
᠌᠌Brains[Abidemi] - avatar
+ 2
because c doesnt have any width or height properties but from no where you just decided c should have one. var c={ width:5,height:10 } or perhaps c is an html dom element like c=document.querySelector("canvas"); //now try your code
16th Apr 2018, 6:07 AM
᠌᠌Brains[Abidemi]
᠌᠌Brains[Abidemi] - avatar
+ 1
thank you gays i'll trying
16th Apr 2018, 6:23 AM
Andrey Nazarov
Andrey Nazarov - avatar
0
correct code: var c = document.querySelector("canvas"); var c = { width: null, height: null }; var w = c.width = window.innerWidth, h = c.height = window.innerHeight;
16th Apr 2018, 6:30 AM
Andrey Nazarov
Andrey Nazarov - avatar
0
it works! Thank you for help!😁
16th Apr 2018, 6:43 AM
Andrey Nazarov
Andrey Nazarov - avatar