Boa tarde! Tudo bem? Espero que sim!
Gostaria de saber o que estou fazendo de errado na minha função anônima, esses são os códigos:
<!DOCTYPE html>
<html lang="pt-br">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style type="text/css">
body {
background-color: black;
}
h1 {
}
p{
}
canvas {
    position:absolute;
    left:35%;
    top:15%;
    margin-left:-120px;
    margin-top:-40px;
}
</style>
<body>
<canvas height="600" width="800"></canvas>
<script>
    var tela = document.querySelector('canvas');
    var pincel = tela.getContext('2d');
    pincel.fillStyle = 'grey';
    pincel.fillRect(0,0,800,800);  
    var c = false; 
    function alert1() {
            alert('thats worked!');
        }
    if (c) {
        alert('Thats worked!'); 
    }
    tela.onclick = function(){
        c=true;
    }
</script>
</body>
</html>Quando eu vinculo a função alert1 ao tela.onclick funciona, mas quando tento fazer uma função anônima no tela.onclick (que nem o código acima) não funciona...
Agradeço desde já!
 
            