0

How would I go about changing css properties of an object in an array?

Title is pretty explanatory, I am creating a game that requires this system. (I tried on line 68 but it just throws an error) https://code.sololearn.com/WnV1LnSJ7ZGB/?ref=app

12th Jul 2020, 10:15 PM
Will
2 Respuestas
+ 2
Will, It looks like you have populated the bulletArray formerly known as the elementArray, as noted by Abhay. But with your code as-is you will still get an error message most likely this one "Uncaught TypeError: Cannot read property 'style' of undefined Line: 68". This due to the for loop: "for(let x = 0; bulletArray.length >= x)" Here you are using the length of the bulletArray as an index to try and gain access to an element that is not there. You need to either add -1 at the end of bulletArray.length or remove the equal sign. Either or will produce the same results in this case. https://code.sololearn.com/WmCbeY150QMh/#js https://www.w3schools.com/js/js_arrays.asp
13th Jul 2020, 6:34 AM
ODLNT
ODLNT - avatar
+ 1
First your array is empty so at array[0] there is nothing ,but assuming there is an object element you want to change property of ,you are doing it right except assigning array[0].style.top which obviously won't get you the current top position for it ,so it returns null ,remove it just or if you wanna get the current top position for that element use, getComputedStyle("element").getPropertyValue("top")
12th Jul 2020, 10:51 PM
Abhay
Abhay - avatar