-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
30 lines (24 loc) · 728 Bytes
/
script.js
File metadata and controls
30 lines (24 loc) · 728 Bytes
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
function Voter(options) {
elem = document.getElementById(options.elem);
var
vote = document.getElementsByClassName('vote')[0],
up = document.getElementsByClassName('up')[0],
down = document.getElementsByClassName('down')[0],
votesCount;
this.setVote = function (votes) {
votesCount = votes >= 0 ? votes : 0;
vote.innerText = votesCount;
};
votesCount = vote.innerText;
up.onclick = function () {
vote.innerText = ++votesCount;
};
down.onclick = function () {
vote.innerText = votesCount > 0 ? --votesCount : 0;
};
}
var voter = new Voter({
elem: 'voter'
});
votes = prompt('Введите начальное количество голосов: ');
voter.setVote(votes);