-
Notifications
You must be signed in to change notification settings - Fork 1
/
Planetco.js
57 lines (41 loc) · 1.62 KB
/
Planetco.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
var river = document.getElementById("river1");
var trees = document.getElementById("tree1");
var crops = document.getElementById("crops1");
var mountains = document.getElementById("mountains1");
var gold = document.getElementById("gold1");
var butterflies = document.getElementById("butterflies1");
var pickeditems = [];
total = 0;
var userwon = document.getElementById("userwon1");
var userlost = document.getElementById("userlost1")
river.addEventListener("click", addriver);
trees.addEventListener("click", addriver);
crops.addEventListener("click", addriver);
mountains.addEventListener("click", addriver);
gold.addEventListener("click", addgold);
butterflies.addEventListener("click", addriver);
function addriver(event) {
total += 350;
document.getElementById("itembought1").innerHTML = "river";
}
function addgold(event) {
total += 425;
document.getElementById("itembought1").innerHTML += " gold";
}
document.getElementById("purchase1").addEventListener("click", runPurchase);
function runPurchase() {
document.getElementById("gamesection").classList.add("hidden");
if(total <= 500) {
document.getElementById("spent1").innerHTML = total;
document.getElementById("gooditem").innerHTML = "river";
userwon.classList.remove("hidden");
} else {
document.getElementById("spent2").innerHTML = total;
userlost.classList.remove("hidden");
}
document.getElementById("purchase1").classList.add("hidden");
}
document.getElementById("tryagain").addEventListener("click", restart);
function restart() {
total = 0;
}