Truncate a string - Basic Algorithm

function truncateString ( str ,  num)  {

 if ( num = str.length ) {

   return str;

 }

 else {

   return str .slice ( 0 , num ) + "..."

 }

}

console.log(truncateString("A-tisket a-tasket A green and yellow basket", 8));

Hey @mariannegreas,

Please describe to us exactly what your problem is, because right now, all I see is code. About the code, next time you want to showcase a code, use the ``` backtick so it is easier for everyone to read.
See this post to find the backtick on your keyboard.
The “preformatted text” tool in the editor (</>) will also add backticks around text.

A mod will do this for you, but next time please do this on your own, so others can read the code easily.

It also seems like this is from a challenge. Can you link the challenge here.
Next time if you need a help from a challenge, you can use the Get Help button on the sidebar.

Anyways, to your issue, it looks like you used a wrong operator for checking equality. The = is an assignment operator. What you want to use is the == operator.

You are right, just noticed I typed = instead of == thank you!!

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).