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()) {
const countArray = ;
let count = 0;
strEntries.forEach(e => {
if (e[1] === character) {
if (count === 2) {
let result = countArray[1] - countArray[0] + 1;
} else {

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?

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

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.