Guest User

lab8q1_jsnotworking

a guest
Jan 16th, 2021
806
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.32 KB | None | 0 0
  1. <!DOCTYPE html>
  2.  
  3. <html lang="en">
  4.     <head>
  5.         <link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@500&display=swap" rel="stylesheet">
  6.         <link href="styles.css" rel="stylesheet">
  7.         <title>Trivia!</title>
  8.     </head>
  9.     <body>
  10.  
  11.         <div class="jumbotron">
  12.             <h1>Trivia!</h1>
  13.         </div>
  14.  
  15.         <div class="container">
  16.  
  17.             <div class="section">
  18.                 <h2>Part 1: Multiple Choice </h2>
  19.                 <hr>
  20.  
  21.                 <!-- TODO: Add multiple choice question here -->
  22.                 <h3 class="question-header">
  23.                     Native to Asia, lesser panda is known by what name?
  24.                 </h3>
  25.  
  26.                 <button type="button" class="q1button">Red Panda</button>
  27.                 <button type="button" class="q1button">Giant Panda</button>
  28.                 <button type="button" class="q1button">Kungfu Panda</button>
  29.  
  30.             </div>
  31.  
  32.             <div class="section">
  33.                 <h2>Part 2: Free Response</h2>
  34.                 <hr>
  35.  
  36.                 <!-- TODO: Add free response question here -->
  37.                 <h3 class="question-header">
  38.                     What is the capital of Ecuador?
  39.                 </h3>
  40.                 <input type="text" id="capname" name="capname">
  41.                 <button type="button" class="q2button">Check Answer</button>
  42.  
  43.             </div>
  44.  
  45.         </div>
  46.     </body>
  47.     <script>
  48.  
  49.             let answers = ["Red Panda", "Quito"]
  50.  
  51.             const buttons = document.querySelectorAll('button.q1button');
  52.  
  53.             for (let i = 0; i < buttons.length; i++) {
  54.  
  55.                if (buttons[i].onclick && buttons[i].innerHTML == answers[0])
  56.                {
  57.                    //change button bg clolour to green
  58.                    buttons[i].style.backgroundColor = "green";
  59.                    //add html text that says correct answer!
  60.                    //TODO
  61.                }
  62.                else if (buttons[i].onclick && buttons[i].innerHTML != answers[0])
  63.                {
  64.                    //change button bg colour to red
  65.                    buttons[i].style.backgroundColor = "red";
  66.                    //add html text that says incorrect answer!
  67.                    //TODO
  68.                }
  69.                else {}
  70.            }
  71.    </script>
  72. </html>
Advertisement
Add Comment
Please, Sign In to add comment