Https://www.codecademy.com/paths/full-stack-engineer-career-path/tracks/fscp-javascript-syntax-part-ii/modules/fecp-practice-javascript-syntax-arrays-loops-objects-iterators/articles/fecp-javascript-practice-arrays-loops-objects-iterators

This is my solution for the second excersize in " JavaScript Practice: Arrays, Loops, Objects, Iterators. Practice intermediate JavaScript concepts with these 3 code challenges.":

function subLength(string, character) {
const strEntries = ;
for (let e of string.split(’’).entries()) {
strEntries.push(e);
};
const countArray = ;
let count = 0;
strEntries.forEach(e => {
if (e[1] === character) {
countArray.push(e[0]);
count++;
}
});
if (count === 2) {
let result = countArray[1] - countArray[0] + 1;
console.log(result);
} else {
console.log(0);
}
};

When I’m cheking the given examples, the answers are right. When I’m clicking “Check Answer” button it says: " Tested subLength('funny', 'n') and it did not return 2 . But when I’m checking the same input by myself it returns 2. What’s wrong?

https://www.codecademy.com/paths/full-stack-engineer-career-path/tracks/fscp-javascript-syntax-part-ii/modules/fecp-practice-javascript-syntax-arrays-loops-objects-iterators/articles/fecp-javascript-practice-arrays-loops-objects-iterators

Hello @9279984279, welcome to the forums! Do you actually return anything from the function, or are you only using console.log()?

Oo, today it accepted my solution (with return)) Yesterday I tried both, with console.log and return, and it didn’t accept the answer. Thanks for help)

1 Like