--- files: [index.html] url: https://cdn.cs50.net/2022/fall/labs/8/trivia/README.md window: [terminal] --- # Lab 8: Trivia Write a webpage that lets users answer trivia questions. ![screenshot of trivia questions](questions.png) ## Implementation Details Design a webpage using HTML, CSS, and JavaScript to let users answer trivia questions. * In `index.html`, add beneath "Part 1" a multiple-choice trivia question of your choosing with HTML. * You should use an `h3` heading for the text of your question. * You should have one `button` for each of the possible answer choices. There should be at least three answer choices, of which exactly one should be correct. * Using JavaScript, add logic so that the buttons change colors when a user clicks on them. * If a user clicks on a button with an incorrect answer, the button should turn red and text should appear beneath the question that says "Incorrect". * If a user clicks on a button with the correct answer, the button should turn green and text should appear beneath the question that says "Correct!". * In `index.html`, add beneath "Part 2" a text-based free response question of your choosing with HTML. * You should use an `h3` heading for the text of your question. * You should use an `input` field to let the user type a response. * You should use a `button` to let the user confirm their answer. * Using JavaScript, add logic so that the text field changes color when a user confirms their answer. * If the user types an incorrect answer and presses the confirmation button, the text field should turn red and text should appear beneath the question that says "Incorrect". * If the user types the correct answer and presses the confirmation button, the input field should turn green and text should appear beneath the question that says "Correct!". Optionally, you may also: * Edit `styles.css` to change the CSS of your webpage! * Add additional trivia questions to your trivia quiz if you would like! ### Walkthrough {% alert primary %} This video was recorded when the course was still using CS50 IDE for writing code. Though the interface may look different from your codespace, the behavior of the two environments should be largely similar! {% endalert %} {% video https://video.cs50.io/WGd0Jx7rxUo %} ### Hints * Use [`document.querySelector`](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector) to query for a single HTML element. * Use [`document.querySelectorAll`](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll) to query for multiple HTML elements that match a query. The function returns an array of all matching elements. {% spoiler "Not sure how to solve?" %} {% video https://video.cs50.io/FLlI7rSSV_M %} {% endspoiler %} ### Testing No `check50` for this lab, as implementations will vary based on your questions! But be sure to test both incorrect and correct responses for each of your questions to ensure that your webpage responds appropriately. Run `http-server` in your terminal while in your `lab8` directory to start a web server that serves your webpage. ## How to Submit 1. Download your `index.html` and `styles.css` files by control-clicking or right-clicking on the file in your codespace's file browser and choosing **Download**. 2. Go to CS50's [Gradescope page](https://www.gradescope.com/). 3. Click "Lab 8: Trivia". 4. Drag and drop your `index.html` and `styles.css` files to the area that says "Drag & Drop". Be sure they have those **exact** filenames! If you upload a file with a different name, the autograder likely will fail when trying to run it, and ensuring you have uploaded files with the correct filenames is your responsibility! 5. Click "Upload". You should see a message that says "Lab 8: Trivia submitted successfully!" {% alert danger %} Per Step 4 above, after you submit, be sure to check your autograder results. If you see `SUBMISSION ERROR: missing files (0.0/1.0)`, it means your file was either not named exactly as prescribed, you uploaded it to the wrong problem, or you did not include all files. Correctness in submissions entails everything from reading the specification, writing code that is compliant with it, and submitting all files with the correct names. If you see this error, you should resubmit right away, making sure your submission is fully compliant with the specification. The staff will not adjust your filenames nor upload files for you after the fact! {% endalert %} Want to see the staff's solution? You can find two ways of solving the problem here! {% spoiler "Creating event listeners with JavaScript" %} ```html Trivia!

Trivia!

Part 1: Multiple Choice


What is the approximate ratio of people to sheep in New Zealand?

Part 2: Free Response


In which country is it illegal to own only one guinea pig, as a lone guinea pig might get lonely?

``` {% endspoiler %} {% spoiler "Creating event listeners with HTML" %} ```html Trivia!

Trivia!

Part 1: Multiple Choice


What is the approximate ratio of people to sheep in New Zealand?

Part 2: Free Response


In which country is it illegal to own only one guinea pig, as a lone guinea pig might get lonely?

``` {% endspoiler %}