my code:
function.js:
export const shortenByWords = (s, n) => {
if (s.length < n) {
return s;
} else {
let string = s.slice(0, n);
for (let i = string.length; i > 0; i--) {
if (string === ' ') {
return ${string.slice(0, i)}...
;
}
}
}
}
solution.js:
import { shortenByWords } from './functions.js';
const longString = 'this string is quiteeeeeeeeeeeeeee long, especially for its age.'
const shortString = 'a short one'
console.log(shortenByWords(longString, 20));
console.log(shortenByWords(shortString, 20));
What have I done wrong?
Please, HELP!