Tell us what’s happening:
my code is supposed to take a string called str1 and return true if its a palindrome (word thats spelt the same forwards and backwards) and false if it isnt. however i keep getting a error saying str1.chartAt is not a function. i was wondering if anyone could help.
i know a for loop would be simpler i was just seeing if it would work in a while loop cus i didnt know what to do.
Your code so far
function isThisAPalindrome(str1) {
var length
length = (str1.length);
var count = 0
let i = 0;
while(i < length){
if (str1.charAt(length-i) === str1.charAt(i)){
count++;
if (count == length){
return true;
}
} else {
return false;
}
i++;
}
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.84 Safari/537.36 OPR/85.0.4341.72
Challenge: Comment Your JavaScript Code
Link to the challenge: