Social post cards with relative times, compact counts, likes
Build the post cards of a small microblogging app. Each card shows who posted, how long ago, the post text, and a row of actions with compact counts like 1.2K. Liking or reposting a post toggles it and updates its count right away.
The starter code includes a fixed “current time” (so the output never changes) and the posts:
const NOW = '2026-03-14T12:00:00Z';
const POSTS = [
{
id: 'p1',
author: { name: 'Priya Raman', handle: 'priyacodes' },
createdAt: '2026-03-14T11:59:15Z',
text: 'Shipped dark mode today. The hardest part was the scrollbar.',
replies: 12, reposts: 0, likes: 999, views: 48210,
},
// ...four more posts
];
Render one card per post, in POSTS order. Each card shows:
@ in front (@priyacodes).<time> element whose dateTime attribute is createdAt exactly and whose text is the time since NOW. With s = whole seconds between createdAt and NOW:
{s}s (for example 45s),{m}m (12m),{h}h (2h),Mon D (Mar 9), plus , YYYY when the year differs from the year of NOW (Dec 31, 2025).aria-label starts with Reply. Clicking it does nothing in this exercise.aria-label starts with Repost, and aria-pressed is "true" or "false".aria-label starts with Like, and aria-pressed is "true" or "false".{count} views, for example 48.2K views.aria-pressed="false").likes + 1 and aria-pressed="true"; clicking again goes back to likes. Repost works the same way with reposts.Every count (replies, reposts, likes and views) is formatted the same way. The decimal is cut off, never rounded up, so a count never shows more than it is:
0, 999),K (1240 → 1.2K, 12999 → 12.9K, 999999 → 999.9K),M (1534200 → 1.5M)..0: 1000 → 1K, 2048 → 2K, 1000000 → 1M.Priya Raman @priyacodes · 45s
Shipped dark mode today. The hardest part was the scrollbar.
Reply 12 Repost 0 Like 999 48.2K views
Click Like Like 1K (aria-pressed="true")
Click Like again Like 999 (aria-pressed="false")
Ana Souza @anasouza · 2h Repost 1K Like 12.9K 999.9K views
Click Like Like 13K
Lena Fischer @lenaf · Dec 31, 2025
999999 must not become 1000K, and 1999 must not become 2K.Math.floor(n / 100) / 10), not from (n / 1000).toFixed(1), which rounds.createdAt slightly after NOW (clock skew) should show 0s, not a negative number.The tests click your buttons and read the screen like a user would. You don’t need test ids or specific class names. They check that:
@handles and texts appear in POSTS order.<time> elements, in post order, have the right dateTime attribute and text.aria-label (Reply, Repost, Like), one of each per post in post order, and the count is read from the button’s text. An icon in the button is fine.aria-pressed before and after clicks.{count} views appear as described.Capitalization and extra spacing don’t matter.