Hi fellas. i’m working on the front end web dvelopment course and got stuck on this question.
A palindrome is a word or sentence that is spelled the same way both forward and backward. Below we’ve provided you with a function that will check if the string provided is a palindrome, but our code is broken.
Using the error messages in the console and your knowledge of debugging, locate and resolve the errors in our code so that it executes properly.
function checkPalindrome(str) {
const reversedStr = ‘’;
for(let i = reversedStr.length-1; i >= 0; i–) {
return reversedStr += str[i];
}
if (reversedStr.split(" “).join(‘’) === reversedStr.split(” ").join(‘’)) {
return The word or sentence, "${str}", is a palindrome!
;
} else {
return The word or sentence, "${str}", is not a palindrome.
;
}
};
console.log(checkPalindrome(‘may a moody baby doom a yam’));
When I run this code it logs
The word or sentence, “may a moody baby doom a yam”, is a palindrome!
Seems working fine but uf i click on “check answer” , “Try checking your code again. You likely have a syntax error” pops up.
Since its one of those Exam questions I don’t want to get a direct answer but can anyone guide me to a right direction?