JS: All the achievement features generate error

0 votes

I'm getting the following error in my console:

Cannot read property 'achievement' of undefined

 

The code I'm using is directly from the online examples (script link and initialise are not included below but are ok).

 

//Show Achievements
function showAchList() {
var result;
var achievementService  = new App42Achievement();
achievementService.getAllAchievements({
    success: function(object)
    {
        var avatarObj = JSON.parse(object);
        result = avatarObj.app42.response.avatars.achievement;
        if(result.length == undefined)
        {
            console.log("Achievement Name is :" + result.name);
            console.log("Description is :" + result.description);
        }
        else
            for(var i = 0;i<result.length;i++){
                console.log("Achievement Name is :" + result[i].name);
                console.log("Description is :" + result[i].description);
            }
    },
    error: function(error)
    {
        console.log("Exception is : " + error)
    }
});
}
asked Sep 30, 2015 in App42 Cloud API-BaaS by dennis.asher (13 points)

1 Answer

0 votes

Hello Dennis,

Greetings for the day!!!

Thanks for sharing your code with us. It seems that there is a mistake in the documentation, thanks for bringing it to our attention. Please use the code snippet below. This should resolve your query.

//Show Achievements
function showAchList() {
var result;
var achievementService  = new App42Achievement();
achievementService.getAllAchievements({
    success: function(object)
    {
        var avatarObj = JSON.parse(object);
        result = avatarObj.app42.response.achievements.achievement;
        if(result.length == undefined)
        {
            console.log("Achievement Name is :" + result.name);
            console.log("Description is :" + result.description);
        }
        else
            for(var i = 0;i<result.length;i++){
                console.log("Achievement Name is :" + result[i].name);
                console.log("Description is :" + result[i].description);
            }
    },
    error: function(error)
    {
        console.log("Exception is : " + error)
    }
});
}

Happy to help you!!!

Regards,
Nishant

answered Sep 30, 2015 by NishantAShephertz (30 points)
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...