Solucionado (ver solução)
Solucionado
(ver solução)
8
respostas

Problemas com AltKey no exercicio de emagrecer a bolinha azul. Logica II, Aula 3 , exer 7. ME AJUDEM!!

O evento altKey deveria emagrecer a bolinha, porém , somente o evento ShiftKey funciona, o altKey não. me ajudem, por favor!


<canvas width="600" height="400"></canvas>

<script>
    var tela = document.querySelector('canvas');
    var pincel = tela.getContext('2d');

    pincel.fillStyle = 'grey';
    pincel.fillRect(0, 0, 600, 400);

    var raio = 10;
    var incremento = 5;

    function desenhaCirculo(evento) {

        var x = evento.pageX - tela.offsetLeft;
        var y = evento.pageY - tela.offsetTop;

        console.log(x + ',' + y);

        if (evento.shiftKey && evento.altKey) {

            alert('Só aperte uma tecla por vez, por favor!');

        } else if(evento.shiftKey && raio + incremento <= 40) {
            raio = raio + incremento;

        } else if(evento.altKey && raio - incremento >= 10) {
            raio = raio - incremento;

        }

        pincel.fillStyle = 'blue';
        pincel.beginPath();
        pincel.arc(x, y, raio, 0, 2 * 3.14);
        pincel.fill();
    }

    tela.onclick = desenhaCirculo;

</script>
8 respostas

Eu testei o seu código e não encontrei problemas. Se não esta funcionando no chrome tente em outro navegador. Caso eu tenha alterado algo no código e não tenha percebido aqui esta ele:

<canvas width="600" height="400"></canvas>

<script>
    var tela = document.querySelector('canvas');
    var pincel = tela.getContext('2d');

    pincel.fillStyle = 'grey';
    pincel.fillRect(0, 0, 600, 400);

    var raio = 10;
    var incremento = 5;

    function desenhaCirculo(evento) {

        var x = evento.pageX - tela.offsetLeft;
        var y = evento.pageY - tela.offsetTop;

        console.log(x + ',' + y);

        if (evento.shiftKey && evento.altKey) {

            alert('Só aperte uma tecla por vez, por favor!');

        } else if(evento.shiftKey && raio + incremento <= 40) {
            raio = raio + incremento;

        } else if(evento.altKey && raio - incremento >= 10) {
            raio = raio - incremento;

        }

        pincel.fillStyle = 'blue';
        pincel.beginPath();
        pincel.arc(x, y, raio, 0, 2 * 3.14);
        pincel.fill();
    }

    tela.onclick = desenhaCirculo;

</script>

Estranho, pois o instrutor recomenda justamente o Chrome para navegador para testar os códigos. Testei outros navegadores, mas o problemas persiste.

Como você pode ver, sem problemas. http://prntscr.com/ml68ys Realmente não encontrei problemas no código nem problemas para executa-lo no chrome.

<canvas width="600" height="400"></canvas>

        <script>
            var tela = document.querySelector('canvas');
            var pincel = tela.getContext('2d');

            pincel.fillStyle = 'grey';
            pincel.fillRect(0, 0, 600, 400);

            var raio = 10;
            var incremento = 10;

            function desenhaCirculo(evento) {

                var x = evento.pageX - tela.offsetLeft;
                var y = evento.pageY - tela.offsetTop;

                console.log(x + ',' + y);

                if(evento.shiftKey){
                    if (raio <= 40)
                        raio = raio + incremento; 
                }

                if(evento.altKey){
                    if(raio > 10){
                        raio = raio - incremento;
                    }
                }

                pincel.fillStyle = 'blue';
                pincel.beginPath();
                pincel.arc(x, y, raio, 0, 2 * 3.14);
                pincel.fill();

            }

            tela.onclick = desenhaCirculo;
        </script>

Oi Luciano tudo bem?

Está apertando o alt da direita ou da esquerda?

É para apertar o da esquerda.

Enzo , copiei e colei o seu código e o problema persiste mano.

To apertando o da esquerda André, o Alt normal, não o Alt Gr.

solução!

Consegue testar o código em outro computador? Para termos 100% de certeza que é problema de infraestrutura, porque para mim tá normal também.

Obrigado galera, fiz como o André mandou e deu certo. Valeu caras!!

Disponha e bons estudos!!!

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software