Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions exercises/part-1/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,11 @@
</head>
<body>






<script src="index.js"></script>
</body>
</html>
21 changes: 21 additions & 0 deletions exercises/part-1/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
let table = document.createElement('table');

function renderDataTable(data, element) {
let tableHeader = table.createTHead();
let row = table.insertRow();


//header
for(let key in data) {
let th= document.createElement("th");
let text = document.createTextNode(key);
th.appendChild(text);
row.appendChild(th);
}


}

const animals = [{name: 'Martin', species: 'Elephant'}, {name: 'Grace', species: 'Tiger'}];
const el = document.getElementById('animals');
renderDataTable(animals, el);
25 changes: 19 additions & 6 deletions short-response.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
## Short Response Section

1. In your own words, answer the following questions: what is the Document Object Model? Why is it useful?

The Document Object Model is a representation of the objects that make up the structure and the content of a webpage.
It is useful as the it can be used to read or modify the content of a webpage and any changes made will be reflected in the webpage.

2. Given some HTML that looks like this:

Expand All @@ -14,8 +15,16 @@
```

What are three different `document` methods that you could use to select the `a` element and store it into a variable?
```javascript
const about = document.querySelectorAll('a')
const about = document.getElementsByClassName('primary')
const about = document.getElementById('about')

```

5. Assuming we have the following code in an HTML file. Describe what the JavaScript code is doing. What would happen when we submit the form?
3. Assuming we have the following code in an HTML file. Describe what the JavaScript code is doing. What would happen when we submit the form?

The JavaScript code is acting on the submition from the form. It takes in the cat name that is inputed in the form and creates an <li> element then appends the cat name to the unordered list in HTML.

```html
<form id="new-cat" action="/" method="POST">
Expand Down Expand Up @@ -44,8 +53,12 @@ What are three different `document` methods that you could use to select the `a`
catList.append(catListItem);
})
```



4. The following HTML and JavaScript creates a button that logs a message to the console each time it is clicked. What line or lines of code could you remove from the JavaScript file and keep the same behavior? Assume that the JavaScript file is being loaded into the HTML via a script tag.

6. The following HTML and JavaScript creates a button that logs a message to the console each time it is clicked. What line or lines of code could you remove from the JavaScript file and keep the same behavior? Assume that the JavaScript file is being loaded into the HTML via a script tag.
To keep the same behavior of logging to the console, lines containing e.preventDefault(); and e.stopPropagation(); would be removed. This is as being able to click the button with its default feature still allows for the message to be logged.

```html
<button id="log">Click to Log to Console</button>
Expand All @@ -62,10 +75,10 @@ What are three different `document` methods that you could use to select the `a`
})
```

7. When developing web applications, what are some examples of events that a user might initiate? Describe at least five.

5. When developing web applications, what are some examples of events that a user might initiate? Describe at least five.
A user might initiate a click event that allows for actions to occur once a specific button is clicked. Mousedown

8. Given the following HTML file, describe what would happen when a user clicks the "Alert" button? What change would you need to make to make our "handleClick" function fire?
6. Given the following HTML file, describe what would happen when a user clicks the "Alert" button? What change would you need to make to make our "handleClick" function fire?

```html
<!DOCTYPE html>
Expand Down