{"id":219,"date":"2024-12-28T10:08:24","date_gmt":"2024-12-28T10:08:24","guid":{"rendered":"https:\/\/lickylip.net\/?p=219"},"modified":"2024-12-28T10:12:56","modified_gmt":"2024-12-28T10:12:56","slug":"jackpot-calculator-2","status":"publish","type":"post","link":"https:\/\/lickylip.net\/index.php\/2024\/12\/28\/jackpot-calculator-2\/","title":{"rendered":"Jackpot Calculator"},"content":{"rendered":"<hr \/>\n<h1>Background<\/h1>\n<p>I need a web app that I can enter the last date that a Bingo Jackpot was last won. The jackpot of 200 euro is won if someone fills a bingo panel in fewer than 40 calls in the first bingo game. If the jackpot isn&#8217;t won 50 euro is added to the jackpot and another call is added to the number of calls required. I&#8217;d like to make an app that can be accessed on a phone. you enter the date that the jackpot was last won and it lists out the jackpot and number of calls each week from then to the day it is run.<\/p>\n<h1>Description<\/h1>\n<p>The <code>calculateJackpot()<\/code> function calculates and displays the jackpot amount and number of calls for a certain number of weeks since the last jackpot win. Here&#8217;s a breakdown of how it works:<\/p>\n<p><strong>1. Get the Last Won Date:<\/strong><\/p>\n<ul>\n<li><code>const lastWonDate = new Date(document.getElementById(\"lastWonDate\").value);<\/code>\n<ul>\n<li>This line gets the date entered by the user in an input field with the ID &#8220;lastWonDate&#8221; and converts it into a <code>Date<\/code> object.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>2. Calculate Weeks Since Last Win:<\/strong><\/p>\n<ul>\n<li><code>const today = new Date();<\/code>\n<ul>\n<li>Gets today&#8217;s date.<\/li>\n<\/ul>\n<\/li>\n<li><code>const weeksSinceWin = Math.ceil((today - lastWonDate) \/ (7 * 24 * 60 * 60 * 1000));<\/code>\n<ul>\n<li>Calculates the difference in milliseconds between today and the last won date.<\/li>\n<li>Divides the difference by the number of milliseconds in a week to get the number of weeks.<\/li>\n<li><code>Math.ceil()<\/code> rounds the result up to the nearest whole number to get the number of whole weeks since the last win.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>3. Initialize Variables:<\/strong><\/p>\n<ul>\n<li><code>let jackpot = 200;<\/code>\n<ul>\n<li>Sets the initial jackpot amount to \u20ac200.<\/li>\n<\/ul>\n<\/li>\n<li><code>let calls = 40;<\/code>\n<ul>\n<li>Sets the initial number of calls to 40.<\/li>\n<\/ul>\n<\/li>\n<li><code>let resultsHTML = \"\";<\/code>\n<ul>\n<li>Creates an empty string to store the HTML output.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>4. Loop Through Weeks:<\/strong><\/p>\n<ul>\n<li><code>for (let i = 1; i &lt;= weeksSinceWin; i++) { ... }<\/code>\n<ul>\n<li>This loop iterates through each week since the last win, starting from week 1.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>5. Calculate Date for Each Week:<\/strong><\/p>\n<ul>\n<li><code>const currentDate = new Date(lastWonDate);<\/code>\n<ul>\n<li>Creates a new <code>Date<\/code> object for the current week, starting with the last won date.<\/li>\n<\/ul>\n<\/li>\n<li><code>currentDate.setDate(lastWonDate.getDate() + (i * 7));<\/code>\n<ul>\n<li>Adds <code>i * 7<\/code> days to the last won date to get the date of the current week.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>6. Format the Date:<\/strong><\/p>\n<ul>\n<li><code>const options = { year: 'numeric', month: '2-digit', day: '2-digit' };<\/code>\n<ul>\n<li>Defines options for formatting the date in European format (dd\/mm\/yyyy).<\/li>\n<\/ul>\n<\/li>\n<li><code>const formattedDate = currentDate.toLocaleDateString('en-GB', options);<\/code>\n<ul>\n<li>Formats the <code>currentDate<\/code> using the specified options.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>7. Build the Output HTML:<\/strong><\/p>\n<ul>\n<li><code>resultsHTML += Week ${i} (${formattedDate}): Jackpot - \u20ac${jackpot}, Calls - ${calls}&lt;br&gt;<\/code>;`\n<ul>\n<li>Appends a line of HTML to <code>resultsHTML<\/code> with the week number, formatted date, current jackpot amount, and number of calls.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>8. Update Jackpot and Calls:<\/strong><\/p>\n<ul>\n<li><code>jackpot += 50;<\/code>\n<ul>\n<li>Increases the jackpot by \u20ac50 for each week.<\/li>\n<\/ul>\n<\/li>\n<li><code>calls += 1;<\/code>\n<ul>\n<li>Decreases the number of calls by 1 for each week.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>9. Display the Results:<\/strong><\/p>\n<ul>\n<li><code>document.getElementById(\"results\").innerHTML = resultsHTML;<\/code>\n<ul>\n<li>Sets the <code>innerHTML<\/code> of an HTML element with the ID &#8220;results&#8221; to display the generated <code>resultsHTML<\/code>.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>In summary, this function takes a date input, calculates how many weeks have passed since that date, and then generates a report showing how the jackpot and number of calls would change over those weeks.<\/strong><\/p>\n<h1>Code<\/h1>\n<pre><code class=\"language-javascript\">function calculateJackpot() {\n    const lastWonDate = new Date(document.getElementById(\"lastWonDate\").value);\n    const today = new Date();\n    const weeksSinceWin = Math.ceil((today - lastWonDate) \/ (7 * 24 * 60 * 60 * 1000)); \n\n    let jackpot = 500;\n    let calls = 50;\n    let resultsHTML = \"\";\n\n    for (let i = 1; i &lt;= weeksSinceWin; i++) {\n        \/\/ Calculate the date for the current week\n        const currentDate = new Date(lastWonDate);\n        currentDate.setDate(lastWonDate.getDate() + (i * 7)); \/\/ Add i weeks to the last won date\n\n        \/\/ Format the date (e.g., \"dd\/mm\/yyyy\") - adjust to your preferred format\n        const options = { year: 'numeric', month: '2-digit', day: '2-digit' };\n        const formattedDate = currentDate.toLocaleDateString('en-GB', options); \/\/ Using European date format\n\n        resultsHTML += `Week ${i} (${formattedDate}): Jackpot - \u20ac${jackpot}, Calls - ${calls}&lt;br&gt;`;\n        jackpot += 50;\n        calls -= 1;\n    }\n\n    document.getElementById(\"results\").innerHTML = resultsHTML;\n}\n<\/code><\/pre>\n<h2>HTML<\/h2>\n<p>This is the HTML that I need to embed in a page to make this work&#8230;<\/p>\n<pre><code class=\"language-html\">&lt;label for=\"lastWonDate\"&gt;Last Jackpot Won Date:&lt;\/label&gt;\n    &lt;input type=\"date\" id=\"lastWonDate\" value=\"2024-11-03\"&gt; \n    &lt;button onclick=\"calculateJackpot()\"&gt;Calculate&lt;\/button&gt;\n    &lt;h2&gt;Results&lt;\/h2&gt;\n    &lt;div id=\"results\"&gt;&lt;\/div&gt;\n    &lt;script src=\"https:\/\/www.lickylip.net\/bingo-calculator\/script.js\"&gt;&lt;\/script&gt;\n<\/code><\/pre>\n<h2>Test<\/h2>\n<h1>Documentation Links<\/h1>\n<p><a href=\"https:\/\/lickylip.net\/index.php\/jackpot-calculator\/\">Deployed Site<\/a><\/p>\n<h1>Log<\/h1>\n<h2>[[2024-12-07]]<\/h2>\n<p>I tried doing this as an apps script web app but that wasn&#8217;t doing what I wanted. So reverted to just doing a JavaScript. This is the first time I&#8217;ve one like this. So going to publish this and try and do more js projects in future.<\/p>\n<h2>[[2024-12-27]]<\/h2>\n<p>Starts at 200 and 40 calls<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Background I need a web app that I can enter the last date that a Bingo Jackpot was last won. The jackpot of 200 euro is won if someone fills a bingo panel in fewer than 40 calls in the first bingo game. If the jackpot isn&#8217;t won 50 euro is added to the jackpot &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/lickylip.net\/index.php\/2024\/12\/28\/jackpot-calculator-2\/\" class=\"more-link\">Read more<span class=\"screen-reader-text\"> &#8220;Jackpot Calculator&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[15],"tags":[],"class_list":["post-219","post","type-post","status-publish","format-standard","hentry","category-coding"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/lickylip.net\/index.php\/wp-json\/wp\/v2\/posts\/219","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lickylip.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lickylip.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lickylip.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lickylip.net\/index.php\/wp-json\/wp\/v2\/comments?post=219"}],"version-history":[{"count":3,"href":"https:\/\/lickylip.net\/index.php\/wp-json\/wp\/v2\/posts\/219\/revisions"}],"predecessor-version":[{"id":223,"href":"https:\/\/lickylip.net\/index.php\/wp-json\/wp\/v2\/posts\/219\/revisions\/223"}],"wp:attachment":[{"href":"https:\/\/lickylip.net\/index.php\/wp-json\/wp\/v2\/media?parent=219"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lickylip.net\/index.php\/wp-json\/wp\/v2\/categories?post=219"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lickylip.net\/index.php\/wp-json\/wp\/v2\/tags?post=219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}