Splice() function is not working

Tell us what’s happening:
Hello, I am getting an error saying that my .splice() is not a function. Here are the instructions:
Truncate a string (first argument) if it is longer than the given maximum string length (second argument). Return the truncated string with a ... ending.

  **Your code so far**

function truncateString(str, num) {
let slicedIt = str.slice("");
let splicedIt = slicedIt.splice(0, num, "...");
return splicedIt.join();

console.log(truncateString("A-tisket a-tasket A green and yellow basket", 8));
  **Your browser information:**

User Agent is: Mozilla/5.0 (X11; CrOS x86_64 14092.57.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.85 Safari/537.36

Challenge: Truncate a String

Link to the challenge:

splice is an array method, you can’t use it on a string

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