Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

JavaScript Difficulty with wondering how to display all answers and then move onto next question

Hi Eliot,

Congrats on finishing your Connections-style game! To display the final row of answers and turn it blue when the player gets the last set correct, you can use JavaScript to dynamically update the DOM and apply styles. Here's how:

Steps:​

  1. Identify the Final Row Element: Ensure the final row has a unique identifier or class to target it in your code.
  2. Update the JS Logic: Add a condition in your game logic that checks if the final set is correct.
  3. Apply the Style Dynamically: Use JavaScript to add a class or style directly to the final row.

Example Solution:​

If your HTML has something like this:


Code:
<span>&lt;<span>div</span> <span>class</span>=<span>"row"</span> <span>id</span>=<span>"final-row"</span>&gt;</span><br>  Final Set<br><span>&lt;/<span>div</span>&gt;</span><br>
In your JavaScript, you can do the following:
Code:
<span>// Example function to handle the final set</span><br><span>function</span> <span>handleFinalSet</span>(<span>correct</span>) {<br>  <span>const</span> finalRow = <span>document</span>.<span>getElementById</span>(<span>"final-row"</span>);<br><br>  <span>if</span> (correct) {<br>    <span>// Add a class to turn the row blue</span><br>    finalRow.<span>classList</span>.<span>add</span>(<span>"correct"</span>);<br>  }<br>}<br>
And in your CSS:

Code:
<span>.correct</span> {<br>  <span>background-color</span>: blue;<br>  <span>color</span>: white;<br>  <span>transition</span>: all <span>0.3s</span> ease; <span>/* Smooth transition */</span><br>}<br>
Finally, call handleFinalSet(true) when the last set is answered correctly.


This way, the row will turn blue when the player gets the last set right. Let me know if you need further help! 😊
 
Hi Eliot,

Congrats on finishing your Connections-style game! To display the final row of answers and turn it blue when the player gets the last set correct, you can use JavaScript to dynamically update the DOM and apply styles. Here's how:

Steps:​

  1. Identify the Final Row Element: Ensure the final row has a unique identifier or class to target it in your code.
  2. Update the JS Logic: Add a condition in your game logic that checks if the final set is correct.
  3. Apply the Style Dynamically: Use JavaScript to add a class or style directly to the final row.

Example Solution:​

If your HTML has something like this:


Code:
<span>&lt;<span>div</span> <span>class</span>=<span>"row"</span> <span>id</span>=<span>"final-row"</span>&gt;</span><br>  Final Set<br><span>&lt;/<span>div</span>&gt;</span><br>
In your JavaScript, you can do the following:
Code:
<span>// Example function to handle the final set</span><br><span>function</span> <span>handleFinalSet</span>(<span>correct</span>) {<br>  <span>const</span> finalRow = <span>document</span>.<span>getElementById</span>(<span>"final-row"</span>);<br><br>  <span>if</span> (correct) {<br>    <span>// Add a class to turn the row blue</span><br>    finalRow.<span>classList</span>.<span>add</span>(<span>"correct"</span>);<br>  }<br>}<br>
And in your CSS:

Code:
<span>.correct</span> {<br>  <span>background-color</span>: blue;<br>  <span>color</span>: white;<br>  <span>transition</span>: all <span>0.3s</span> ease; <span>/* Smooth transition */</span><br>}<br>
Finally, call handleFinalSet(true) when the last set is answered correctly.


This way, the row will turn blue when the player gets the last set right. Let me know if you need further help! 😊
Hi Simon,

This is my html for the site


HTML:
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Connections</title>
    <link
      rel="icon"
      type="image/x-icon"
      href="img/background/Connections logo.svg"
    />
    <link rel="stylesheet" href="Connections.css" />
  </head>
  <body>
    <div class="logo">INFOBORES</div>
    <div id="connavigationbar">
      <a href="Hi.html">Hi</a>
      <a href="about_me.html">Bio</a>
      <a href="Art.html">Art</a>
      <a href="cv.html">CV</a>
      <a href="Games.html">Play</a>
    </div>
    <div id="containercon">
      <div class="connectionscontainercategories">
        <div class="row">1</div>
        <div class="row">2</div>
        <div class="row">3</div>
        <div class="row">4</div>
      </div>
      <div class="connectionscontainer">
        <div class="col"></div>
        <div class="col"></div>
        <div class="col"></div>
        <div class="col"></div>

        <div class="col"></div>
        <div class="col"></div>
        <div class="col"></div>
        <div class="col"></div>

        <div class="col"></div>
        <div class="col"></div>
        <div class="col"></div>
        <div class="col"></div>

        <div class="col"></div>
        <div class="col"></div>
        <div class="col"></div>
        <div class="col"></div>
      </div>
      <button class="submit" onclick="CheckAnswers()">Submit</button>
    </div>

    <script src="Connectionsdata.js"></script>
    <script src="Connections.js"></script>
  </body>
</html>
 

Buy us a coffee!

Buy me a coffee.
Back
Top Bottom