Skip to content

Commit 4589537

Browse files
committed
Add an exercise for week 1
1 parent c8ce792 commit 4589537

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/week1/exercise/app.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
3+
{
4+
function fetchJSON(url, cb) {
5+
const xhr = new XMLHttpRequest();
6+
xhr.open('GET', url);
7+
xhr.responseType = 'json';
8+
xhr.onload = () => cb(xhr.response);
9+
xhr.send();
10+
}
11+
12+
function main() {
13+
const select = document.getElementById('select-category');
14+
const ul = document.getElementById('prize-list-container');
15+
16+
select.addEventListener('change', () => {
17+
const url = `http://api.nobelprize.org/v1/prize.json?category=${select.value}`;
18+
console.log('url', url);
19+
});
20+
}
21+
22+
window.onload = main;
23+
}

src/week1/exercise/index.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
7+
<title>Exercise</title>
8+
</head>
9+
<body>
10+
<select id="select-category">
11+
<option disabled selected>Select a category</option>
12+
<option value="physics">physics</option>
13+
<option value="chemistry">chemistry</option>
14+
<option medicine="physics">medicine</option>
15+
<option value="peace">peace</option>
16+
<option value="literature">literature</option>
17+
<option value="economics">economics</option>
18+
</select>
19+
<ul id="prize-list-container"></ul>
20+
<script src="app.js"></script>
21+
</body>
22+
</html>

0 commit comments

Comments
 (0)