Uncaught SyntaxError: Unexpected end of input

0

My code is generating error and I searched for syntax error but can not find it here and Sublime Text 2 has no broker. can you help me? Here is the code:

var Padrao = {

    /**
    * Init
    */
    init : function(){

        //Exibe Tela de Login/Minha Conta
        $('.login').click(Padrao.abreLogin);

        //Exibe Carrinho de Compras
        $('.carrinho-botao').click(Padrao.exibeCarrinho);

        //Chama o carrousel de Banner
        Padrao.carrouselBanner();
    },

    //Exibe Tela de Login/Minha Conta
    abreLogin : function(){
        $('.minha-conta').toggle(200);
    },

    //Exibe Carrinho de Compras
    exibeCarrinho : function(){
        $('.carrinho-aberto').toggle(200);
    },

    //Carrousel de banner
    carrouselBanner : function(){

        //recupera a qtd de elementos da lista
        var elementos = $('.destaque-banner ul li').length;

        //atribui automatico o valor de width para a ul
        $('.destaque-banner ul').css({width : 990 * elementos});


        //define e imprime a quantidade de bullets de acordo com o numero de elementos
        for(var i = 0; i < elementos; i++){
            if(i == 0){
                $('.bullets-area ul').append('<li><a href="javascript:void" index="' + parseInt(i) + '" class="sel"> x </a></li>');
            } else {
                $('.bullets-area ul').append('<li><a href="javascript:void" index="' + parseInt(i) + '"> x </a></li>');
            }
        }

        $('.bullets-area ul li a').click(function(){
            var desloca = $(this).attr('index');
            //alert(desloca);
            $('.destaque-banner ul').animate({'margin-left': desloca * -1000});
        });
    }
};

$(Padrao.init);
    
asked by anonymous 12.02.2014 / 19:48

4 answers

2

You can use javacriptlint for this.

Just copy and paste the code there and it shows you syntax errors.

The site is a lint tool. Unfortunately it does not have a page in the wiki for lint tools in Portuguese yet, but they are tools that analyze the code looking for syntax errors and some bad practices. The vast majority of programming languages have such tools.

    
12.02.2014 / 19:53
0

Friend, try to put a comma at the end for example:

 $('.bullets-area ul li a').click(function(){
            var desloca = $(this).attr('index');
            //alert(desloca);
            $('.destaque-banner ul').animate({'margin-left': desloca * -1000});
        });
    },
};

$(Padrao.init);
    
12.02.2014 / 20:21
0

There's nothing wrong with the code itself. The problem is hidden in Javascript links that are added by the code.

Instead of:

<a href="javascript:void">x</a>

Make:

<a href="javascript:;">x</a>
    
13.02.2014 / 13:39
-2

Here is your corrected code

var Padrao = {

    /**
    * Init
    */
    init : function(){

        //Exibe Tela de Login/Minha Conta
        $('.login').click(Padrao.abreLogin);

        //Exibe Carrinho de Compras
        $('.carrinho-botao').click(Padrao.exibeCarrinho);

        //Chama o carrousel de Banner
        Padrao.carrouselBanner();
    },

    //Exibe Tela de Login/Minha Conta
    abreLogin : function(){
        $('.minha-conta').toggle(200);
    },

    //Exibe Carrinho de Compras
    exibeCarrinho : function(){
        $('.carrinho-aberto').toggle(200);
    },

    //Carrousel de banner
    carrouselBanner : function(){

        //recupera a qtd de elementos da lista
        var elementos = $('.destaque-banner ul li').length;

        //atribui automatico o valor de width para a ul
        $('.destaque-banner ul').css({width : 990 * elementos});


        //define e imprime a quantidade de bullets de acordo com o numero de elementos
        for(var i = 0; i < elementos; i++){
            index = parseInt(i,10); // faltou um parametro aqui, parseInt(string, radix), você não tinha passado o radix
            if(i === 0){ // como era uma comparação de tipos o lint pede que seja feita uma comparação usando "==="
                $('.bullets-area ul').append('<li><a href="javascript:void" index="' + index  + '" class="sel"> x </a></li>');
            } else {
                $('.bullets-area ul').append('<li><a href="javascript:void" index="' + index  + '"> x </a></li>');
            }
        }

        $('.bullets-area ul li a').click(function(){
            var desloca = $(this).attr('index');
            //alert(desloca);
            $('.destaque-banner ul').animate({'margin-left': desloca * -1000});
        });
    }
};

$(Padrao.init);

At line 40 was complaining about missing the second parameter no parseInt() on recommendation it should get 2 parameters where the second is optional parseInt(string, radix)

  

Parameter - (string) Required. The string to be parsed

     

Description - (radix) Optional. A number (from 2 to 36) that represents the numeral system to be used

At line 41 the was complaining about the comparison type then the comparison was changed from == to ===

    
12.02.2014 / 20:56