LearnFrenzy
Sign in Take a free test

String Methods · Find the Error · Question 12

Bug: the course is not found Answer, explanation & discussion

  • Find the error
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 12 Back to Exercise

The code below runs without an error, but its result is wrong. Which statement correctly identifies the bug?

main.js
const courses = ["JavaScript Basics", "Python for Data", "Advanced JavaScript"];
const query = "javascript";
console.log(courses.filter((c) => c.includes(query)));
  • A filter cannot use includes
  • B includes needs a regex
  • C includes is case-sensitive – compare c.toLowerCase().includes(query.toLowerCase()) Correct
  • D The query must be trimmed
Correct Answer: Option C

"JavaScript" does not contain "javascript". Lower-casing both sides finds both JavaScript courses.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links