+ 2
Please help me debug this simply game code
The page is simply supposed to tell you what color you have touched. I don't seem to find the error yet I have done this before and it worked. https://code.sololearn.com/WpV1UzKW5hzT/?ref=app
4 Respuestas
+ 6
If you << have done this before and it worked >>, it's probably because you previously set the background color with the inlined 'style' attribute of elements, rather than actually do it with global stylesheet, and your JS code 'element.style.background' will return only the inlined declaration (if some)...
You can fix your code by using instead the 'window.getComputedStyle(element)' method:
alert(window.getComputedStyle(this).backgroundColor);
Use of 'background' property will return whole background properties, so I'll change it to 'backgroundColor' to get only the css 'background-color' property as your goal is to just display the colir used...
Anyway, format of returned color value is rgba(), so if you want to display the hexadecimal code of it, you need to parse and convert it :P
+ 2
cool it works now
https://code.sololearn.com/WpV1UzKW5hzT/?ref=app
0
not sure, but maybe you should print the element's id :) it's easier and try use JSON.stringify() function to check your element's properties
0
@luis sanchez JSON.stringify() doesn't help. It just shows that the background if empty while it clearly isn't :(