WishICouldCode
New Coder
Im not sure what I did wrong, but the Wood amount in the Campain tab and the Follower Cost goes NaN when clicked. HELP!
HTML:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- All the Crazy CSS -->
<style>
body {font-family: Arial;}
/* Style the tab */
.tab {
overflow: hidden;
border: 1px solid #ccc;
background-color: #f1f1f1;
}
/* Style the buttons inside the tab */
.tab button {
background-color: inherit;
float: left;
border: none;
outline: none;
cursor: pointer;
padding: 14px 16px;
transition: 0.3s;
font-size: 17px;
}
/* Change background color of buttons on hover */
.tab button:hover {
background-color: #ddd;
}
/* Create an active/current tablink class */
.tab button.active {
background-color: #ccc;
}
/* Style the tab content */
.tabcontent {
display: none;
padding: 6px 12px;
border: 1px solid #ccc;
border-top: none;
}
</style>
</head>
<body>
<h2>Sirrulith</h2>
<p>For years mosters have roamed the land.</p>
<p>You seek to change that...</P>
<div class="tab">
<button class="tablinks" onclick="openCity(event, 'Campaign')">Campaign</button>
<button class="tablinks" onclick="openCity(event, 'Camp')">Camp</button>
<button class="tablinks" onclick="openCity(event, 'Empowerments')">Empowerments</button>
</div>
<div id="Campaign" class="tabcontent">
<h3>Campaign</h3>
<div class="clickToGain">
<div class="soulThings">
<button onclick="soulsClick(1)" >Purge</button>
<br />
Souls: <span id="souls">0</span>
</div>
<div class="woodThings">
<button onclick="woodClick(1)">Cut Tree</button>
<br />
Wood: <span id="wood">0</span>
</div>
</div>
<div class="buyables">
<div class="followerThings">
<button onclick="buyFollower()">Inlist</button>
<br />
Followers: <span id="follower">0</span>
<br />
Follower Cost: <span id="followerCost">10</span> souls
<br />
</div>
</div>
<div class="campThings">
<button onclick="buyCamps()">Camp</button>
<br />
Camp: <span id="camps">0</span>
<br/>
Camp Cost: <span id="campsCost">15</span> wood
</div>
</div>
</div>
</div>
<div id="Camp" class="tabcontent">
<h3>Camp</h3>
</div>
<div id="Empowerments" class="tabcontent">
<h3>Empowerments</h3>
<p>Tokyo is the capital of Japan.</p>
</div>
<script>
// Hello! If you are here, I hope you aren't cheating! :D
// All the resource stuff
var souls = 0;
checkSouls()
var wood = 0;
checkWood()
var soulsAllNum = 0;
function soulsClick(number){
souls = souls + number;
document.getElementById("souls").innerHTML = souls;
checkSouls()
};
function woodClick(number){
wood = wood + number;
document.getElementById("wood").innerHTML = wood;
checkWood()
};
// Stuff you can buy
var follower = 0;
function buyFollower(){
var followerCost = Math.floor(10 * Math.pow(1.50,follower)); //works out the cost of this follower
if(souls >= followerCost){ //checks that the player can afford the follower
follower = follower + 1; //increases number of followers
souls = souls - followerCost; //removes the souls spent
document.getElementById('follower').innerHTML = follower; //updates the number of followers for the user
document.getElementById('souls').innerHTML = souls;
};
var nextCostFollowers = Math.floor(10 * Math.pow(1.5,follower)); //works out the cost of the next follower
document.getElementById('followerCost').innerHTML = nextCostFollowers; //updates the follower cost for the user
checkSouls()
};
var camps = 0;
function buyCamps(){
var campsCost = Math.floor(10 * Math.pow(1.1,camps));
if(wood >= campsCost){
camps = camps + 1;
wood = wood - campsCost;
document.getElementById('camps').innerHTML = camps;
document.getElementById('wood').innerHTML = wood;
};
var nextCostCamps = Math.floor(10 * Math.pow(1.5,camps)); //works out the cost of the next follower
document.getElementById('campsCost').innerHTML = nextCostCamps; //updates the follower cost for the user
};
function checkSouls(){
if (souls <= 10){
document.getElementById("followerBuyButton").disabled = true;
} else {
document.getElementById("followerBuyButton").disabled = false;
};
}
function checkWood(){
if (wood <= 15){
document.getElementById("campBuyButton").disabled = true;
} else {
document.getElementById("campBuyButton").disabled = false;
};
}
// Tick settings
window.setInterval(function(){
soulsClick(follower);
}, 1500);
//Tab Stuff
function openCity(evt, cityName) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(cityName).style.display = "block";
evt.currentTarget.className += " active";
}
</script>
</body>
</html>