Home / Widgets / Flashes
Duplicate Snippet

Embed Snippet on Your Site

Flashes

Code Preview
html
<h1 id="roundMessage" class="wp-block-heading has-text-align-center"></h1>
<div id="newsflashes">
  <!-- Newsflashes will be dynamically inserted here -->
</div>
<script>
  // Array of possible newsflashes
  const newsflashArray = [
    "Market prices for IT have surged due to increased demand.",
    "The Auto industry faces a shortage of raw materials.",
    "Agriculture exports have hit a record high this quarter.",
    "Defense contracts have been awarded to several nations.",
    "Financial Services sector reports a decline in profits.",
    "New technology innovations are driving growth in the IT sector.",
    "A global recession is impacting the Auto industry.",
    "Farmers are protesting against new agricultural policies.",
    "Defense spending has increased by 10% this year.",
    "Banks are offering lower interest rates to boost the economy.",
  ];
  // Function to display 3 random newsflashes
  function displayRandomNewsflashes() {
    const newsflashes = document.getElementById("newsflashes");
    newsflashes.innerHTML = ""; // Clear previous newsflashes
    // Shuffle the newsflash array and pick the first 3
    const shuffledNewsflashes = newsflashArray.sort(() => 0.5 - Math.random());
    const selectedNewsflashes = shuffledNewsflashes.slice(0, 3);
    // Display the selected newsflashes
    selectedNewsflashes.forEach((newsflash) => {
      const p = document.createElement("p");
      p.textContent = newsflash;
      newsflashes.appendChild(p);
    });
  }
  // Function to display the round message and newsflashes
  function displayRoundMessage(roundNumber) {
    // Update the round message
    const roundMessage = document.getElementById("roundMessage");
    roundMessage.textContent = `Round ${roundNumber} has begun!`;
    // Display 3 random newsflashes
    displayRandomNewsflashes();
  }
      displayRoundMessage(gameState.round); // Display round message and newsflashes for the new round
    } else {
      alert("Game over! You've reached the final round.");
    }
  }
  // Ensure the new module works with existing event listeners
  document.addEventListener("DOMContentLoaded", () => {
    document.getElementById("startButton").addEventListener("click", initializeGame);
    document.getElementById("progressButton").addEventListener("click", progressRound);
  });
</script>

Comments

Add a Comment