Question 6
Back to Exercise
The code below stops with an uncaught error. Which statement correctly describes the problem?
const word = "level";
console.log(word.reverse() === word ? "Palindrome" : "Not a palindrome");
- A It prints Palindrome
- B It prints Not a palindrome
- C SyntaxError
- D TypeError: word.reverse is not a function – strings have no reverse; use [...word].reverse().join("") Correct
Correct Answer: Option D
reverse is an Array method. Convert, reverse and join: [...word].reverse().join("") === word.
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!