Skip to content

Commit c462186

Browse files
sudoworkyangsu
authored andcommitted
Added Review Problem
1 parent e9b041b commit c462186

3 files changed

Lines changed: 39 additions & 0 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# JavaScript Practice Review Problem
2+
3+
## Identifying Child Elements
4+
5+
The purpose of this problem is to learn a little bit about how the document object model (DOM) works along with event handlers, and to review closures. In this exercise, you'll be adding click handlers to items in a list. The behavior of the handler should be to pop up an alert that contains the position of the child. In other words, when clicking the first list item, it should pop up an alert with the contents `0` because it is the 0-th child.
6+
7+
In the `./review/` directory, you will find two files: `review.html` and `review.js`. The first file is going to be the test environment for running your code. Modify the code in `review.js` to add these click handlers.
8+
9+
## Hints
10+
11+
* Use [`document.getElementById()`](http://www.w3schools.com/jsref/dom_obj_core_document.asp) to retrieve a DOM element
12+
* Refer to the [DOM Node][] API for some helpful methods.
13+
14+
[DOM Node]: http://www.w3schools.com/jsref/dom_obj_node.asp

review/review.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE html>
2+
3+
<html>
4+
<head><title>JavaScript Review Problem: Identifying Child Elements</title></head>
5+
<body>
6+
<h3 id="list-title"></h3>
7+
<ul id="list" style="background-color: #EEE;"></ul>
8+
<script>
9+
var numItems = Math.floor(Math.random() * 10 + 5),
10+
list = document.getElementById('list'),
11+
i, currItem;
12+
document.getElementById('list-title').innerHTML = numItems + "-list";
13+
console.log('Generating ' + numItems + ' list items.');
14+
for (i = 0; i < numItems; i++) {
15+
currItem = document.createElement('li');
16+
currItem.innerHTML = "Click me!";
17+
list.appendChild(currItem);
18+
}
19+
</script>
20+
<script src="./review.js"></script>
21+
</body>
22+
</html>

review/review.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
(function () {
2+
// ...
3+
}());

0 commit comments

Comments
 (0)