ardon-income/calculate.js

71 lines
1.9 KiB
JavaScript

"use strict";
//Licensed under the Apache License 2.0. See license file for information.
// Ardon Income Calculator v3.0 stable.
// Written by Josh Mudge
// Ad Mejorem Dei Glorium
function calculate() {
var numReg = /^\d+$/;
//Get input
var blocks = document.getElementById("blocks").value;
var one = document.getElementById("one").value;
var gov = document.getElementById("gov").value;
var design = document.getElementById("design").value;
var embassies = document.getElementById("embassies").value;
var capital = document.getElementById("capital").value;
var infra = document.getElementById("infra").value;
var chain = document.getElementById("chain").value;
var town = document.getElementById("town").value;
var city = document.getElementById("city").value;
var metro = document.getElementById("metro").value;
if (blocks.match(numReg))
{
//Do nothing.
}
else
{
//Tells them to enter only numbers.
alert("Please enter only numbers in this field.");
}
var gold = +blocks / 10
console.log(gold)
var infra = +infra / 1000 * 0.005
console.log(infra)
var one = +one / 1000 * 0.01
console.log(one)
var chain = +chain * 0.0025
console.log(chain)
var design = +design / 1000 * 0.015
console.log(design)
var gov = +gov * 0.02
console.log(gov)
var embassies = +embassies * 0.02
console.log(embassies)
var capital = +capital * 0.025
console.log(capital)
var town = +town * 0.005
console.log(town)
var city = +city * 0.01
console.log(city)
var metro = +metro * 0.01
console.log(metro)
var percent = +one + +design + +gov + +embassies + +capital + +infra + +chain + +town + +city + +metro
console.log(percent)
var total = +gold * +percent + +gold
var total = total.toFixed(0);
console.log(total)
var date = Date();
console.log(date)
//Show result
alert("Your income is " + total + " Gold");
document.getElementById("Income").innerHTML = "Your Income is " + total + " Gold";
}