forked from kbalog/web-programming
-
Notifications
You must be signed in to change notification settings - Fork 1
/
exercise5.js
34 lines (26 loc) · 938 Bytes
/
exercise5.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
* Exercise #5: jQuery color picker
*/
$(document).ready(function () {
// collect colors in an array
var colors = [];
var range = ["00", "33", "66", "99", "cc", "ff"];
for (var r = 0; r < range.length; r++) {
for (var g = 0; g < range.length; g++) {
for (var b = 0; b < range.length; b++) {
colors.push("#" + range[r] + range[g] + range[b]);
}
}
}
// create colored tiles
for (var i = 0; i < colors.length; i++) {
var tile = $("<div></div>");
// TODO set class="choice" for the tile and set background color to colors[i]
// Hint: you can use the css() method to set the background color
// TODO append tile to the element with id="colors"
}
// when a tile is clicked
$(".choice").click(function () {
// TODO: get the color of the tile and write it to the element id="selected"
});
});