summaryrefslogtreecommitdiff
path: root/wk8/pset/trivia/index.html
blob: 9b854d6fdabac59a2f66392e0b511e211b1e3f51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<!DOCTYPE html>

<html lang="en">

    <head>
        <link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@500&display=swap" rel="stylesheet">
        <link href="styles.css" rel="stylesheet">
        <title>Trivia!</title>
        <script>
            // TODO: Add code to check answers to questions
            document.addEventListener('DOMContentLoaded', function() {

                let correct = document.querySelector('.correct');
                correct.addEventListener('click', function() {
                    correct.style.backgroundColor = 'green';
                    document.querySelector('#feedback1').innerHTML = 'Correct!';
                });

                let incorrects = document.querySelectorAll('.incorrect');
                for (let i = 0; i < incorrects.length; i++) {
                    incorrects[i].addEventListener('click', function() {
                        incorrects[i].style.backgroundColor = 'red';
                        document.querySelector('#feedback1').innerHTML = 'Incorrect';
                    });
                };

                document.querySelector('form').addEventListener('submit', function(event) {
                    event.preventDefault();
                    if (document.querySelector('#big').value == 'Earl Grey') {
                        document.querySelector('#big').style.backgroundColor = 'green';
                        document.querySelector('#feedback2').innerHTML = 'Correct!';
                    } else {
                        document.querySelector('#big').style.backgroundColor = 'red';
                        document.querySelector('#feedback2').innerHTML = 'Inorrect';
                    }
                });
            });
        </script>
    </head>

    <body>
        <div class="header">
            <h1>Trivia!</h1>
        </div>

        <div class="container">
            <div class="section">
                <h2>Part 1: Multiple Choice </h2>
                <hr>

                <h3>How many beans do Hemingway's cats have per paw?</h3>

                <button class="incorrect">3</button>
                <button class="incorrect">4</button>
                <button class="correct">5</button>
                <button class="incorrect">6</button>

                <p id="feedback1"></p>

            </div>

            <p></p>

            <div class="section">
                <h2>Part 2: Free Response (case sensitive)</h2>
                <hr>
                <!-- TODO: Add free response question here -->

                <h3>What is my favorite mixture of tea?</h3>

                <form>
                    <input autocomplete='off' id='big' placeholder='Answer' type='text'>
                    <input type='submit'>
                </form>

                <p id="feedback2"></p>

            </div>
        </div>
    </body>

</html>