1

I have this function taken from here: smart way to shorten long strings with javascript

String.prototype.trunc = String.prototype.trunc ||
  function(n){
      return (this.length > n) ? this.substr(0, n-1) + '…' : this;
  };

var randNumb = Math.floor((Math.random() * 100000000000000000));
randNumb = randNumb.toString();
randNumb = randNumb.trunc(16);

Today when i tried to use my webpage i got the following error:

Uncaught (in promise) TypeError: randNumb.trunc is not a function
at main (displayData.js:53)
at HTMLButtonElement.onclick ((index):1)

It worked fine yesterday and i haven't changed this part of the code since then. Does anyone have an idea what has happened?

Edit: I found the problem... I apparently changed some code without meaning to. Thanks for the help anyway.

Community
  • 1
  • 1
Storbod
  • 29
  • 1
  • 3
  • `randNumb` is typeof number? – kind user Apr 22 '17 at 11:33
  • Where do you get `randNumb`? – ibrahim mahrir Apr 22 '17 at 11:34
  • 1
    Questions seeking debugging help ("**why isn't this code working?**") must include the desired behavior, a *specific problem or error* and *the shortest code necessary* to reproduce it **in the question itself**. Questions without **a clear problem statement** are not useful to other readers. See: [How to create a Minimal, Complete and Verifiable example](https://stackoverflow.com/help/mcve/). – Andreas Apr 22 '17 at 11:37
  • i get the number from Math.random() and then randNumb = randNumb.toString(); – Storbod Apr 22 '17 at 11:38
  • Can you post more code??? – ibrahim mahrir Apr 22 '17 at 11:47
  • "It worked fine yesterday and i haven't changed this part of the code since then" — This type of problem is usually caused by changing something without meaning to. Creating an [mcve] will usually help you identify the problem. – Quentin Apr 22 '17 at 11:47

0 Answers0