41 lines
1007 B
JavaScript
41 lines
1007 B
JavaScript
"use strict";
|
|
//Licensed under the Apache License 2.0. See license file for information.
|
|
|
|
function calculate() {
|
|
var emeralds = 0
|
|
var tenblocks = 0
|
|
var tenthbonus = 0
|
|
var numReg = /^\d+$/;
|
|
|
|
//Get input
|
|
|
|
var blocks = document.getElementById("blocks").value;
|
|
var tenblocks = document.getElementById("tenblocks").value;
|
|
var twentyfifth = document.getElementById("twentyfifth").value;
|
|
|
|
if (tenblocks.match(numReg))
|
|
{
|
|
//Do nothing.
|
|
}
|
|
else
|
|
{
|
|
//Tells them to enter only numbers.
|
|
|
|
alert("Please enter only numbers in this field.");
|
|
}
|
|
|
|
var emeralds = +blocks / 1000
|
|
console.log(emeralds)
|
|
var tenblocks = +tenblocks / 1000 * 0.001
|
|
console.log(tenblocks)
|
|
var twentyfifth = +twentyfifth / 1000 * 0.0025
|
|
var tenthbonus = +emeralds + +tenblocks +twentyfifth
|
|
var total = tenthbonus.toFixed(4);
|
|
console.log(tenthbonus)
|
|
|
|
//Show result
|
|
alert("Your secret message is " + total);
|
|
document.getElementById("Answer").innerHTML = "Your secret message is " + total;
|
|
|
|
}
|