Hi guys Ive done the proyect in vscode i tried the code and it worked then I pasted the code inside freecodecamps and its saying some of the test doesnt provide the correct solution. I typed every test in my vscode editor and every test answed the question correctly. The following are the test`s i checked.
console.log(palindrome(“eye”));
console.log(palindrome(“_eye”));
console.log(palindrome(“race car”));
console.log(palindrome(“not a palindrome”));
console.log(palindrome(“A man, a plan, a canal. Panama”));
console.log(palindrome(“never odd or even”));
console.log(palindrome(“nope”));
console.log(palindrome(“almostomla”));
console.log(palindrome(“My age is 0, 0 si ega ym.”));
function palindrome(str) {
let upSideStr=[ ];
let normalStr=[];
for(let i=0; i<str.length; i++){
if(isNumOrLetter(str[i])==false){
str[i]=" ";
}else{
normalStr.push(str[i].toLowerCase());
upSideStr.unshift(str[i].toLowerCase());
}
}
console.log(upSideStr);
console.log(normalStr);
return isEqual(upSideStr,normalStr);
}
function isNumOrLetter(a){
let question;
let aNumber=parseInt(a);
a.charCodeAt(a)>=97&&a.charCodeAt(a)<=122 ? question=true:
a.charCodeAt(a)>=65&&a.charCodeAt(a)<=90 ? question=true:
aNumber>=0&&aNumber<=9 ? question=true:
question=false;
return question;
}
function isEqual(str1,str2){
let isTrue=true;
for(let i=0; i<str1.length&&isTrue==true; i++){
str1[i]==str2[i] ? isTrue=true:
isTrue=false;
}
return isTrue;
}
console.log(palindrome("eye"));
console.log(palindrome("_eye"));
console.log(palindrome("race car"));
console.log(palindrome("not a palindrome"));
console.log(palindrome("A man, a plan, a canal. Panama"));
console.log(palindrome("never odd or even"));
console.log(palindrome("nope"));
console.log(palindrome("almostomla"));
console.log(palindrome("My age is 0, 0 si ega ym."));
console.log(palindrome("1 eye for of 1 eye."));
console.log(palindrome("0_0 (: /-\ :) 0-0"));
console.log(palindrome("five|\_/|four"));
I changed it with str[i]=String.fromCharCode(32) and it keeps giving me the same results on vs code the correct answers in freecodecamp in most of the cases fails the test
Thanks for the advice, in which cases i should use ternary?. I know i haven`t use the best practices, i havent finished the course in freecamp but i wanted to take the challenge for the fun of it. I will do it again once i finish the course.
Personally, I would always avoid variable assignments inside the expressions. Although, you do see it from time to time I don’t really think it is the correct use of a ternary.
If you need to do assignments to more than one variable I would suggest not using a ternary.