{searchResults.map((course) => <div> <li> <Link to={`/course/${course.courseCode}/`}> {course.courseCode} - {course.description} </Link> </li> <hr /> </div> )} extend this code so it shows "sorry, not found" if searchResults is empty
GPT-3.5
GPT-6 Astra
{searchResults.length > 0 ? (
searchResults.map((course) => (
<div key={course.courseCode}>
<li>
<Link to={`/course/${course.courseCode}/`}>
{course.courseCode} - {course.description}
</Link>
</li>
<hr />
</div>
))
) : (
<p>sorry, not found</p>
)}
What changed
The code is nearly identical: both use a ternary on searchResults.length > 0, both add key={course.courseCode} to the div, and both fall back to a paragraph. The real difference is in what surrounds it. GPT-3.5 explains the change clearly, then undercuts itself with a closing note claiming the original code had “no need to add the key attribute” because it “was not being used in a list.” The original was a map, so the key was missing there too. That sentence is simply wrong and could confuse a learner.
Astra returns only the code, with no explanation, and keeps the requested wording exactly (“sorry, not found”) where GPT-3.5 capitalized it. Astra also adds the key without mentioning it, which is a small missed chance to teach. Neither answer points out that an li wrapped in a div isn’t valid inside a list, so both inherit that quirk unchanged.