CSCI 344: Spring 2025

Advanced Web Technology

CSCI 344: Spring 2025

UNCA Logo

Quiz 2b: JavaScript Programming with the DOM

Paper Quiz

Once you complete the written portion of the quiz, please complete the tasks below.

Set-Up

Quiz 2b Starter Files Quiz 2b Answers

Your directory structure should look something like this (it’s OK if your file structure looks different, so long as the quizzes folder looks like the one below):

csci344
├── homework
├── lectures
├── quizzes
│   ├── quiz01
│   ├── quiz02a
│   └── quiz02b
├── tutorials
...

Task 1: Analyzing User Data [20pts]

Please answer the following two questions based on the users array, located in task01/main.js and displayed below:

const users = [
    { id: 1, name: "Alice", age: 25, isActive: true, role: "admin" },
    { id: 2, name: "Bob", age: 30, isActive: false, role: "user" },
    { id: 3, name: "Charlie", age: 22, isActive: true, role: "moderator" },
    { id: 4, name: "David", age: 35, isActive: true, role: "user" },
    { id: 5, name: "Eve", age: 28, isActive: false, role: "admin" },
    { id: 6, name: "Frank", age: 40, isActive: true, role: "moderator" },
];

1.1. Array of usernames [10pts]

Inside of task01/main.js, use the map array method to create an array of names (array of strings). Output this array to the console. Expected result:

1.2. Array of active users [10pts]

Inside of task01/main.js, use the filter array method to create an array of only active users. Output this array to the console. Expected result:

Task 2: Fetch and Display Wikipedia Data [20pts]

2.1. Fetching Wikipedia data [10pts]

Create an asynchronous function called getWikipediaInfo in task01/main.js:

Here are some sample queries (click to see the data):

Notice that even though the search term does not match the title of the article exactly, the Wikipedia API is smart enough to figure out the correct article and redirect to it.

When you’re done implementing your getWikipediaArticle function, test it by:

2.2. Displaying the data visually [10pts]

Create another function in task02/main.js called dataToHTML. This function will take a Wikipedia data object as an argument and return an HTML representation of the Wikipedia page that includes:

Here’s a suggested HTML format:

<section class="card">
    <img src="https://picsum.photos/150">
    <div>
        <h2>Title of Wikipedia Page</h2>
        Information from the "extract_html" data field
    </div>
</section>

Testing your dataToHTML function

Test your dataToHTML function by:

If you did it correctly, you should see a screen that looks like the one pictured below:

What to Submit

Before you submit

Verify that you’ve completed both required tasks. Then, add the links to your tasks to your homepage under the quiz section (see Sarah’s homepage for an example): https://vanwars.github.io/csci344/.

Submit to the Moodle

Please Read Carefully: To submit Quiz 2b, paste the following links into the Moodle under the Quiz 2b submission section:

  1. A link to your homepage on GitHub pages.
  2. A link to your GitHub code repository (where your code files are stored).

If your GitHub is not working for whatever reason, just zip your COMPLETED quiz02b folder and upload it to the Moodle.

A note on timestamps

When I am grading the quiz, I will look at the timestamps for your Quiz 2b submission on GitHub to ensure that I am only grading code that was submitted before the end of class on the day of the quiz.