Question: I have the following HTML:

```
<div id="container"><div id="textOnLeft">{{someDynamicText}}</div><div id="btnOnRight"><button></button></div></div>

```

The button should be always to the right of the dynamic text.
Case the width of the text + width of the button are over the width of the container - the text should be ellipsis.

Please you guidance.

Thanks,
Ampo.

Answer: 
Your best bet is to store the value in a cookie with an expiry time. That way you can leave it up to the browser to decide whether the joke ID has expired or not. This is a pure JS example of how you could do it:

```
// Will return a joke id between the min and max values. Once the joke ID has 
// been generated for the day, it is persisted in a cookie until midnight.
function getJokeId(minId, maxId) {
  var jokeId = getCookie('joke');

  if (jokeId !== null) {
    return jokeId;
  }

  var expire = new Date();
  expire.setHours(23,59,59,0);

  jokeId = Math.floor(Math.random()*(maxId - minId + 1) + minId);

  document.cookie = 'joke='+jokeId+';expires='+expire.toGMTString()+';path=/';

  return jokeId;
}

// Just a helper function for accessing cookies in JS - could be replaced with 
// jQuery plugin or similar if needed.
function getCookie(name) {
  var value = "; " + document.cookie;
  var parts = value.split("; " + name + "=");

  if (parts.length == 2) {
    console.log('Found joke ID from cookie');
    return parts.pop().split(";").shift();
  }

  console.log('No joke ID found - new one needed');
  return null;
}

getJokeId(0, 5);

```

Here's a JS Fiddle of the example code: <https://jsfiddle.net/edcs/0Lpg9ro6/>
If it's OK for each user to get their own random value, but for it to only change once a day, use a cookie or `.localStorage` to remember how long it is since they last got a new value.

Otherwise, you'd have to implement your own random number generator. The one built-into JS doesn't allow you to specify your own "seed".

From [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random):

> 
> The implementation selects the initial seed to the random number generation algorithm; it cannot be chosen or reset by the user.
> 
> 
>