Limit random image to display x time for specified period of time
<p><strong><em>Functionality:</em></strong></p>

<p>A randomised game result image will be displayed in the image container depending on the game result played by the user. </p>

<p>However, there are some criteria that are bounded to the randomly displayed game result image. They are:</p>

<p>1.) The randomly displayed images will only be displayed for x times daily. After the x times has been displayed, the resulting image will not be randomised anymore.</p>

<p>2.) The randomly generated image will be displayed x times daily for a period of time: meaning -> image A will be randomly generated for a month from today(23/12/2016 00:00:00) and will end on (23/01/2017 23:59:59). Each day, the image will only be randomly generated 6 times.</p>

<p><strong><em>Issue:</em></strong></p>

<p>At this time, I have set the randomly generated method based on the different game result scenario. It does not read the period and the number of times now. </p>

<p>I have got no idea on how to proceed with the following conditions: All I have tried which resulted in error is that I have set a for loop but the following for loop that I have set is only for daily random generation. </p>

<p>Hence, I have got no idea how to achieve the following with the criteria that were stated.</p>

<p>Please advise/ help.</p>

<p><strong><em>Code</em></strong></p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>//With reference to prize display for Jackpot Spin
var Prize_1 = ["lib/image/Prize/CeHK.png", "lib/image/Prize/CuSet.png"];
var Prize_2 = ["lib/image/Prize/Suunch.png", "lib/image/Prize/Esit.png", "lib/image/Prize/Mold's.png", "lib/image/Prize/Kiis.png", "lib/image/Prize/Ai.png", "lib/image/Prize/shra.png" ];
var Prize_3 = ["lib/image/Prize/Moto.png", "lib/image/Prize/Saung.png", "lib/image/Prize/Timnd.png", "lib/image/Prize/Blety.png", "lib/image/Prize/Raco.png", "lib/image/Prize/Chaai.png"];

/*Check the slot result: depending on slot result will display the respective result page*/
if ((that.items1[that.result1].id == 'goods-64') &amp;&amp; (that.items2[that.result2].id == 'goods-64') &amp;&amp; (that.items3[that.result3].id == 'gold-64')) {

    //Randomise Winning - Prize 1
    var random_Winning_1 = Math.floor(Math.random() * Prize_1.length);
    var showPrize_1 = Prize_1[random_Winning_1];

    //Display Winning Prize: Prize 1
    $("#Winnings_Description").attr('src', showPrize_1).show();

    $('#VoucherPreview').fadeIn();

} else if ((that.items1[that.result1].id == 'energy-64') &amp;&amp; (that.items2[that.result2].id == 'energy-64') &amp;&amp; (that.items3[that.result3].id == 'cash-64')) {

    //Randomise Winning - Prize 2
    var random_Winning_2 = Math.floor(Math.random() * Prize_2.length);
    var showPrize_2 = Prize_2[random_Winning_2];

    $("#Winnings_Description").attr('src', showPrize_2).show();

    $('#VoucherPreview').fadeIn();

} else if ((that.items1[that.result1].id == 'cash-64') &amp;&amp; (that.items2[that.result2].id == 'cash-64') &amp;&amp; (that.items3[that.result3].id == 'build-64')) {

    //Randomise Winning - Prize 3
    var random_Winning_3 = Math.floor(Math.random() * Prize_3.length);
    var showPrize_3 = Prize_3[random_Winning_3];

    //Display Winning Prize: Prize 3
    $("#Winnings_Description").attr('src', showPrize_3).show();

    $('#VoucherPreview').fadeIn();

} else if ((that.items1[that.result1].id == 'build-64') &amp;&amp; (that.items2[that.result2].id == 'build-64') &amp;&amp; (that.items3[that.result3].id == 'build-64')) {

    //Display GAP as Prize Winning
    //Display Winning Prize: GAP
    $("#Winnings_Description").attr('src', "lib/image/Prize/Gap.png").show();

    $('#VoucherPreview').fadeIn();

} else if ((that.items1[that.result1].id == 'staff-64') &amp;&amp; (that.items2[that.result2].id == 'staff-64') &amp;&amp; (that.items3[that.result3].id == 'staff-64')) {

    //Display Guess as Prize Winning
    //Display Winning Prize: Guess
    $("#Winnings_Description").attr('src', "lib/image/Prize/Guess.png").show();

    $('#VoucherPreview').fadeIn();

} else {

    //If user has got no winning sets
    alert("game lost: Loser");
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div id="VoucherPreview" align="center" style="position:absolute; width:1920px; height:1080px; background-repeat: no-repeat; display: none; z-index=14; top:0px; left:1921px; "&gt;
  &lt;img id="Winnings_Description" style="position:absolute; top:333px; left:543px; z-index=99; margin:auto;"&gt;
&lt;/div&gt;</code></pre>
</div>
</div>
</p>

<p>Plunker: <a href="https://plnkr.co/edit/Iyai0QsJHTjjfODRzw21?p=catalogue" rel="nofollow noreferrer">https://plnkr.co/edit/Iyai0QsJHTjjfODRzw21?p=catalogue</a></p>