Scan the code to replace what is necessary from the requirements and each code is separate so it isn't all in one code for each requirement. Don't show the balance untill either the Demo or Play with Crypto has been clicked. have it so once Demo has been clicked it enable the user to bet any amount without a finite limited balance ONLY ON THE DEMO MODE while if the user
clicked on Play with Crypto it will be selected and the balance will show up but won't use what was used for
code
Balance: $${item.balance}</span>
</p>
<p class="timestamp">${item.timestamp}</p>`;
historyContent.prepend(historyItem);
});
} but do not show an history item result if user did not clicked <button id="submitBet">Place Bet</button> while having a number in the <input type="number" id="betAmount" value="0" onkeypress="return isNumberKey(event)" oninput="validateInput(this)" step="any" min="0" placeholder="Enter amount"> without messing up any functionalities. when the user is not on the page it will keep going but so the multiplier won't keep being 0.04x to fit the requirements definitely, precisely and perfected without any shortcuts for each requirements:
</section>
<script>
// JavaScript to randomize the top and right positions and animation parameters
const spans = document.querySelectorAll('span');
spans.forEach(span => {
const top = Math.random() * 100 + 'vh'; // Random top position within viewport height
const right = Math.random() * 100 + 'vw';// Random right position within viewport width
const delay = Math.random() * 3;
const duration = Math.random() * 2 + 1; // Duration between 1 and 3 seconds
span.style.top = top;
span.style.right = right;
span.style.setProperty('--delay', delay);
span.style.setProperty('--duration', duration);
// Remove left initial styling
span.style.left = 'initial';
});
</script>
Assistant
To implement the requirements, you need to modify the existing code to handle demo and crypto modes separately, manage balance display, and update history accordingly. Here's how you can achieve this:
1. Mode Selection and Balance Display
First, ensure that the balance is not displayed until either the demo or crypto mode is selected. Then, update the balance display based on the selected mode.
javascript
// Initially hide balance display
document.getElementById('balance').style.display = 'none';
// Function to toggle mode and update balance display
function toggleMode(demo) {
isDemoMode = demo;
document.getElementById('demoMode').classList.toggle('selected', demo);
document.getElementById('cryptoMode').classList.toggle('selected', !demo);
updateBalanceDisplay();
displayHistory();
}
// Update balance display based on mode
function updateBalanceDisplay() {
if (isDemoMode) {
document.getElementById('balance').style.display = 'block';
document.getElementById('balance').textContent = 'Balance: ∞';
} else {
document.getElementById('balance').style.display = 'block';
document.getElementById('balance').textContent = `Balance: $${cryptoBalance.toFixed(2)}`;
}
}
// Add event listeners for mode buttons
document.getElementById('demoMode').addEventListener('click', () => toggleMode(true));
document.getElementById('cryptoMode').addEventListener('click', () => toggleMode(false));
2. Disable Mode Buttons After Bet Submission
Once a bet is submitted, disable the mode buttons until the next round.
javascript
// Disable mode buttons when bet is submitted
submitBetButton.addEventListener('click', function() {
document.getElementById('demoMode').disabled = true;
document.getElementById('cryptoMode').disabled = true;
});
// Enable mode buttons at the start of a new round
function initializeGame() {
document.getElementById('demoMode').disabled = false;
document.getElementById('cryptoMode').disabled = false;
}
3. Manage Demo Mode Betting
In demo mode, allow betting without a finite balance.
javascript
// Function to handle bet submission
function handleBetSubmission() {
if (isDemoMode) {
// Allow any bet amount in demo mode
const betAmount = parseFloat(betAmountInput.value);
// Proceed with the bet logic without checking balance
// ...
} else {
// Check balance and proceed with bet logic in crypto mode
const betAmount = parseFloat(betAmountInput.value);
if (betAmount <= cryptoBalance) {
cryptoBalance -= betAmount;
// Proceed with the bet logic
// ...
} else {
alert("Insufficient balance.");
}
}
}
4. Update History
Only update history when playing with crypto mode and a bet is submitted.
javascript
// Function to add to history
function addToHistory(multiplier, profit) {
if (!isDemoMode) {
const bet = parseFloat(betAmountInput.value);
if (bet > 0) {
const result = {
timestamp: new Date().toLocaleString(),
betAmount: bet.toFixed(2),
multiplier: multiplier,
total: profit.toFixed(2),
balance: cryptoBalance.toFixed(2)
};
history.unshift(result);
localStorage.setItem('crashGameHistory', JSON.stringify(history));
displayHistory();
}
}
}
// Function to display history
function displayHistory() {
if (!isDemoMode) {
historyContent.innerHTML = '';
if (localStorage.getItem('crashGameHistory')) {
history = JSON.parse(localStorage.getItem('crashGameHistory'));
}
history.forEach((item) => {
const historyItem = document.createElement('div');
historyItem.classList.add('historyItem');
const profitLoss = parseFloat(item.total);
const color = profitLoss > 0 ? 'var(--neon-green)' : profitLoss < 0 ? 'var(--neon-red)' : 'yellow';
const sign = profitLoss > 0 ? '+' : '';
historyItem.innerHTML = `
<p>
<span>Bet: $${item.betAmount} Multiplier: ${item.multiplier}x
${profitLoss !== 0 ? (profitLoss > 0 ? `Profit: $${item.total}` : `Loss: $${Math.abs(profitLoss).toFixed(2)}`) : ''}
Balance: $${item.balance}</span>
</p>
<p class="timestamp">${item.timestamp}</p>`;
historyContent.prepend(historyItem);
});
} else {
historyContent.innerHTML = '';
}
}
5. Responsive History Table with Pagination
To create a responsive table with pagination, you can modify the displayHistory function to use a table structure and implement pagination logic.
html
<!-- Add a table structure for history -->
<div id="historyContent">
<table id="historyTable">
<thead>
<tr>
<th>Timestamp</th>
<th>Bet</th>
<th>Multiplier</th>
<th>Profit/Loss</th>
<th>Balance</th>
</tr>
</thead>
<tbody id="historyBody"></tbody>
</table>
<div id="pagination"></div>
</div>
javascript
// Function to display history in a table with pagination
function displayHistory() {
if (!isDemoMode) {
const historyTableBody = document.getElementById('historyBody');
historyTableBody.innerHTML = '';
const paginationDiv = document.getElementById('pagination');
paginationDiv.innerHTML = '';
if (localStorage.getItem('crashGameHistory')) {
history = JSON.parse(localStorage.getItem('crashGameHistory'));
}
const itemsPerPage = 10; // Number of items to display per page
const totalPages = Math.ceil(history.length / itemsPerPage);
for (let i = 0; i < totalPages; i++) {
const pageButton = document.createElement('button');
pageButton.textContent = i + 1;
pageButton.onclick = function() {
displayPage(i);
};
paginationDiv.appendChild(pageButton);
}
displayPage(0); // Display the first page by default
function displayPage(pageIndex) {
historyTableBody.innerHTML = '';
const start = pageIndex * itemsPerPage;
const end = start + itemsPerPage;
for (let i = start; i < end && i < history.length; i++) {
const item = history[i];
const row = document.createElement('tr');
row.innerHTML = `
<td>${item.timestamp}</td>
<td>$${item.betAmount}</td>
<td>${item.multiplier}x</td>
<td style="color: ${parseFloat(item.total) > 0 ? 'var(--neon-green)' : parseFloat(item.total) < 0 ? 'var(--neon-red)' : 'yellow'}">
${parseFloat(item.total) > 0 ? '+' : ''}${item.total}
</td>
<td>$${item.balance}</td>
`;
historyTableBody.appendChild(row);
}
}
} else {
document.getElementById('historyContent').innerHTML = '';
}
}
This setup ensures that the balance is hidden until a mode is selected, demo mode allows unlimited betting, and history is displayed in a responsive table with pagination only when playing with crypto mode.