Leaderboard Archive
Javascript May 4, 2026

Spot the bug: This async function should fetch and return data.

async function getData(url) {
  fetch(url)
    .then(res => res.json())
    .then(data => {
      return data
    })
}
A fetch needs async/await not .then()
B The return inside .then() returns to .then(), not to getData — getData returns undefined
C res.json() should be res.text()
D url needs quotes
Explanation
This is a very common mistake. When you use return inside a .then() callback, it returns the value to the .then() chain — not to the outer async function. So getData() returns undefined. Fix it by using await: const data = await fetch(url).then(r => r.json()); return data.
📝
Reviewed by CodeShot Editorial
Every challenge is code-reviewed by senior developers to ensure accuracy and real-world relevance. Learn more.

Ready for your shot?

Join thousands of developers solving one logic puzzle every morning.

Solve Today's Challenge →