• in
InterCourses
CoursesBlogs
0
← Introduction to JavaScript
○What is JavaScript?○Your First JavaScript Code○Data Types○Type Checking
○Declaring Variables○let and const in Practice○Operators○Type Conversion
○Conditionals○Switch Statement○For Loops○While Loop○Break and Continue
○Defining Functions○Arrow Functions○Scope○Closures○Project - Calculator○Function Expressions
○Arrays○Array Mutation Methods○Array Search and Slice○Array Iteration Methods○Multidimensional Arrays○Destructuring○Array Reverse and Sort○Array Fill○Array Find and Includes○Array Flat and FlatMap○Array Reduce, Some, and Every
○Objects○Object Methods and Destructuring○JSON○Math and Date○Date Basics
○02 Template Literals○String Methods○Regular Expressions
○Higher-Order Functions○Callbacks○map, filter, and reduce○Recursion○Project - Data Transform Pipeline
○OOP Introduction○Classes○Inheritance○Encapsulation
○Asynchronous JavaScript○Promises and Async Await●Async API Simulation

Async API Simulation

In real apps, async code often coordinates multiple network requests and handles partial failures gracefully.

Your Task

You are given fake API helpers that return Promises:

  • fetchUser() resolves to { id: 1, name: "Alex" } after a short delay.
  • fetchPosts(userId) resolves to an array of posts.
  • fetchNotifications(userId) resolves to an array of notifications.

Implement:

  1. loadDashboard() async function that:
    • fetches the user first,
    • then fetches posts and notifications in parallel with Promise.all.
  2. Return an object:
javascript
{
  userName: "Alex",
  postCount: 3,
  unreadCount: 2
}
  1. If any request fails, catch the error and return:
javascript
{
  userName: "Unknown",
  postCount: 0,
  unreadCount: 0
}
  1. Display in #output: "Alex | posts: 3 | unread: 2".
Hint 1
1 / 3
HINT 1

Use Promise.all([...]) to run promises in parallel.

Loading editor…
READY
intercourses
javascript