300-920 · Question #49
Drag and Drop Question Drag and drop the code to complete the JavaScript snippet so that it: - retrieves the details of an individual user - checks what licenses they have already - updates their…
The correct answer is people; licenses; people; person. Explanation This question tests knowledge of a common REST API pattern for user license management. The code performs three operations using a people collection and person objects. The Code Structure ``javascript // 1. Retrieve individual user from the collection const response…
Question
Exhibit
Answer Area
Drag items
Correct arrangement
- people
- licenses
- people
- person
Explanation
Explanation
This question tests knowledge of a common REST API pattern for user license management. The code performs three operations using a people collection and person objects.
The Code Structure
// 1. Retrieve individual user from the collection
const response = await fetch('/api/[1]/' + userId); // → people
const person = await response.json();
// 2. Check existing licenses
const userLicenses = person.[2]; // → licenses
// 3 & 4. Update account with new license
await fetch('/api/[3]/' + userId, { // → people
method: 'PUT',
body: JSON.stringify([4]) // → person
});
Why Each Item Goes Where It Does
Position 1 - people
You're fetching from the collection endpoint (/api/people/{id}). The collection is called people (plural), not person. This retrieves the individual user's record from the group of all users.
Position 2 - licenses
After fetching the user, you access the licenses property on the returned object to inspect what they already have. This is a field on the user object, not a standalone variable.
Position 3 - people
The update also targets the same people collection endpoint. You push changes back to /api/people/{id}. The collection name doesn't change just because you're writing instead of reading.
Position 4 - person
The body of the PUT/PATCH request is the individual user object (person), now containing the newly assigned license. You're sending the whole updated object back, not just the licenseId in isolation.
Common Mistakes
| Mistake | Why It's Wrong |
|---|---|
Using person at positions 1 or 3 | person is the object variable, not the API endpoint path |
Using licenseId at position 4 | You update the whole person object; licenseId alone isn't a valid request body here |
Swapping licenses and person | licenses is a property to read, person is the object to write |
Using people at position 2 | Position 2 accesses a field on the user object - that field is licenses, not the collection |
The key insight: people is the collection (API path), person is one instance of it (the JS object), and licenses is a property of that instance.
Topics
Community Discussion
No community discussion yet for this question.
