My result comes out correct, but I get the 'exceeded execution timeout of 40 seconds' error.
I have done this:

export const shortenByWords = (s, n) => {
if(s.length > n) {
for(let i = n + 1; i > 0; i++) {
if(s === ' '){
return s.slice(0, i) + '...';
}
}
} else {
return s
}
}

    salmankhawar could you explain the condition of your for loop? It's unclear what you intend by let i = n + 1; i > 0; i++

    P.S. For future tasks also include the task description and submission results. Maybe as screenshots.

    Okay I copied the wrong one, here's the correct one.:
    export const shortenByWords = (s, n) => {
    if(s.length > n) {
    for(let i = n; i < s.length; i++) {
    if (s === ' ')

      
    return s.slice(0, i) + '...';
    
    }
    } else {
    return s
    }
    }

    Results Screenshot here:

    Did some changes:

    export const shortenByWords = (s, n) => {
      if(s.length > n) {
        for(let i = 0; i < s.length; i++){ 
          if (s[i] === ' ' && i > n) return s.slice(0, i) + '...';
        }
      } else {
        return s
      }
    }

      Write a Reply...