HELP! My function does not return value

I’m trying to get my function to return the value of list_name_star but, it doesn’t seems to work. I will appreciate any help on this.

        function githubTopStars() {
            var list_name_star = [];
            var xhr = new XMLHttpRequest();
            xhr.open('GET', 'https://api.github.com/search/repositories?q=language:python&sort=stars');
            xhr.setRequestHeader('Content-Type', 'application/json');
            xhr.onload = function () {
                if (xhr.status === 200) {
                    var data = JSON.parse(xhr.responseText);
                    var repo_dicts = data.items;
                    var repo_dict = repo_dicts[0];
                    var repo_dict_key = Object.keys(repo_dict);
                    var repo_dicts_key = Object.keys(repo_dicts);
                    document.getElementById('test').innerHTML = 'Total repositories: ' + String(data.total_count);
                    document.getElementById('test2').innerHTML = 'Repositories returned: ' + repo_dicts.length;
                    document.getElementById('test3').innerHTML = 'Keys: ' + repo_dict_key.length;

                    for (rkey = 0; rkey < repo_dicts.length; rkey++) {
                        var name_star_count = [];
                        repo_dict = repo_dicts[rkey];
                        name_star_count.push(repo_dict.name, repo_dict.stargazers_count);
                        list_name_star.push(name_star_count)
                        // console.log(name_star_count);

                        // console.log('Stars:', repo_dict.stargazers_count);

                    }
                 //   console.log(list_name_star);
                    return list_name_star;
                    /*   for (key = 0; key < repo_dict_key.length; key++){
                        console.log(repo_dict_key[key]);
                    }
                    console.log(Object.keys(data)); */
                  //  console.log(data);
                }
                else {
                    alert('Request failed. Request status of ' + xhr.status);
                }
            };
            xhr.send();
        }
        console.log(githubTopStars());

Thank you for checking my code.

Yes, I will like to use the returned list to create a chart with Google chart.

Thanks let me try that

I got it to work and here is what i came up with:

Thanks for everything

1 Like