"Uncaught SyntaxError: Unexpected identifier"

I know this question has been asked many times, but I tried to find a solution, but did not get SO from the available questions.

I am very new to Javascript. I am trying to create an application for calculating examples in android using cordova. For this, I created the cordova plugin. But I constantly get two questions.

"Uncaught SyntaxError: Unexpected identifier", source: file:///android_asset/www/js/index.js (36)

here is the index.java code and targetCalculation () target.

    var app = {

// Application Constructor
initialize: function() {
    this.bindEvents();
},
bindEvents: function() {
    document.addEventListener('deviceready', this.onDeviceReady, false);
    document.getElementById("btnCalculate").addEventListener("click", performCalculation);
},
onDeviceReady: function() {
    app.receivedEvent('deviceready');
},
// Update DOM on a Received Event
receivedEvent: function(id) {
    var parentElement = document.getElementById(id);
    var listeningElement = parentElement.querySelector('.listening');
    var receivedElement = parentElement.querySelector('.received');

    listeningElement.setAttribute('style', 'display:none;');
    receivedElement.setAttribute('style', 'display:block;');

    console.log('Received Event: ' + id);
}

performCalculation: function (){
    console.log("in index.html");
    var success = function() {
        alert("Success");
    };
    var error = function(message) {
    alert("Oopsie! " + message);
    };
    performAddition(20,10,success,error);
}

};  
app.initialize();

Here is my second exception that I get.

"Uncaught SyntaxError: Unexpected token .", source: file:///android_asset/www/js/calculation.js (3)

and here is the .js calculation code

var calculationPlugin = {
console.log("calculation");
    performAddition: function(first_number, second_number, successCallback, errorCallback) {
    console.log("addition");
        cordova.exec(
            successCallback, // success callback function
            errorCallback, // error callback function
            'CalculationPlugin', // mapped to our native Java class called "CalculationPlugin"
            'addition', // with this action name
            [{                  // and this array of custom arguments to create our entry
                "firstNumber": first_number,
                "secondNumber": second_number,

            }]
        );
     }
}
+4
source share
2 answers

First syntax error

You are missing the "," after the receivedEvent function.

Second syntax error

- , , . .

+5

: app.receivedEvent('deviceready'); this.receivedEvent('deviceready');

. , .

+1

Source: https://habr.com/ru/post/1654641/


All Articles