Attempting to transform a grid of small square divs by assigning them random background colors, I am facing an issue.
Although my syntax appears correct and the console is not reporting any errors, it seems like the .css() method refuses to accept the genColor function I have implemented.
While looking for a solution, I came across this thread which shares similarities with my situation, but unfortunately, the proposed fix did not resolve my problem.
function genColor() {
'use strict';
var hexes = '0123456789ABCDEF'.split('');
var color = '#';
for (var i = 0; i < 6; i++){
color += hexes[Math.floor(Math.random * 16)];
}//end for loop
return color;
This function is then utilized in the following code snippet:
function highlightSquare(){
'use strict';
$('.square').on('mouseenter', function () {
$(this).css('background', genColor());
});
If anyone can provide assistance, I would greatly appreciate it. Despite encountering examples that suggest otherwise, I am unable to pinpoint why this specific implementation is failing.
On a side note, the inclusion of 'use strict'; serves the purpose of preventing JSLint warnings within the Brackets editor, without directly impacting the functionality of the aforementioned code.