Please help me debug this simply game code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

8th Jul 2017, 9:27 PM
Mame86
Mame86 - avatar
4 Answers
+ 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
8th Jul 2017, 9:44 PM
visph
visph - avatar
8th Jul 2017, 9:52 PM
Mame86
Mame86 - avatar
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
8th Jul 2017, 9:36 PM
luis sanchez
luis sanchez - avatar
0
@luis sanchez JSON.stringify() doesn't help. It just shows that the background if empty while it clearly isn't :(
8th Jul 2017, 9:41 PM
Mame86
Mame86 - avatar