0

Here is my assignment;

Write a web application using HTML, CSS, and JS that does the following:

Display a list of users fetched using this API: https://jsonplaceholder.typicode.com/users. When you click on a user, display a list of albums associated with that user by using this API https://jsonplaceholder.typicode.com/albums. When you click on an album, display a list of images associates with that album by using this API

I'm not sure how to do this I think that I need to create a class and use the data from the first API to create members after that I'm kind of lost. I've learned basics of HTML CSS and JS, but going over all of that and searching the internet doesn't seem to be helping. If anyone knows a good source of information on the subject I would be very greatful.

5
  • You're stuck on what? Fetching the data, modelling your data, or displaying your data? What have you tried? Start with fetching the data, there are millions of resources on doing this - try the new fetch API available on modern browsers, or jQuery's $.ajax. Commented Jan 23, 2017 at 12:14
  • You'll be working with JSON objects, you can try this website: youmightnotneedjquery.com because it teaches some basics of JavaScript without any lib. Commented Jan 23, 2017 at 12:17
  • SO is a question and answer site for specific problems and not a forum for details covering a broad area. Commented Jan 23, 2017 at 12:21
  • Your question is missing the 3rd API link (for the pictures) Commented Jan 23, 2017 at 12:24
  • I'm sorry, I should have explained that I am new to web development, thank you for the help this should be all I need. Commented Jan 29, 2017 at 15:37

1 Answer 1

2

Basicly you need to make AJAX calls to the given APIs and populate some target container <div>s with the result.

Here is a very basic example using jQuery showing a list of users and their respective albums when a user is clicked

<div id="users"></div>

<script type="text/javascript" src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script>
$.ajax({
    url: "https://jsonplaceholder.typicode.com/users",
    success: function(users) {
        for (var i = 0; i < users.length; i++) {
            var user = document.createElement("div");
            user.id = 'user-' + users[i].id;
            user.className = 'user';
            span = document.createElement('span');
            span.innerHTML = users[i].name;
            albums = document.createElement('ul');
            albums.className = 'albums';
            user.appendChild(span);
            user.appendChild(albums);
            user.addEventListener("click", function(){
                var that = this;
                var userId = this.id.split('-')[1];
                var dest = this.getElementsByClassName('albums')[0];
                dest.innerHTML = '';
                $.ajax({
                    url: "https://jsonplaceholder.typicode.com/albums",
                    success: function(albums) {
                        for (var j = 0; j < albums.length; j++) {
                            if (albums[j].userId == userId) {
                                console.log(albums[j].userId, ' == ', userId);
                                var li = document.createElement('li');
                                li.innerHTML = albums[j].title;
                                dest.appendChild(li);
                            }
                        }
                    }
                })
            });
            document.getElementById('users').appendChild(user);
        }
    }
});
</script>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.