Try with:
var cellId = Math.floor(Math.random() * 24 + 1);
document.getElementById(cellId).setAttribute("name", "key");
But the user can simply look at the source of the page to find the key
for check if the key is found
function clic(e)
{
if( attempts <= 0){
console.log("no more attempts");
return;
}
if( e.target.getAttribute('name') == 'key' ){
console.log('key found');
}
else{
console.log('key NOT found');
--attempts;
}
}
Here you find the working jsFiddle