javascript function parameters

I’ve just started using Wix and developing a site. By no means an expert i’m relatively comfortable with Javascript & jQuery. I want a text box to expand when clicked so was delighted today when i got a message saying that this feature request is now available.

I’m following the support article https://support.wix.com/en/article/creating-an-expandable-text-box-with-a-show-more-link-using-wix-code

However, despite copying and pasting the code (amending it to use the name of the text box i have placed on my page see below)

// how many characters to include in the shortened version 
const shortTextLength = 40;  
// read the full text and store it in the fullText variable
 fullText = $w("#myTextElement").text;  
// // grab the number of characters defined in shortTextLength and store them in the shortText  
shortText = fullText.substr(0, shortTextLength) + "...";  
// set the contents of the text element to be the short text 
$w("#myTextElement").text = shortTextLength;

When I select Preview as instructed I get the error message :

Wix code SDK error: The text parameter that is passed to the text method cannot be set to the value 50. It must be of type string.

Whatever I do I cannot stop this error, even if i hardcode the value in the substr function call I still get the same error.

I can stop the error occuring by quoting the value of shortTextLength but then no text is displayed.

Is this a problem as it is new functionality or am i missing something very simple?

Try instead of:
$w(" #myTextElement ").text = shortTextLength;
this:
$w(" #myTextElement ").text = shortText;

Thanks Giri, well spotted!