-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculator.js
21 lines (19 loc) · 1.13 KB
/
calculator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/** calculator.js provides a method triggered by clicking the Calculate! button on the web page.
* Sets the "results" element's inner HTML either to a message providing $ wasted per class skipped or an error message.
* Written by mrsillydog, Fall 2020
*/
// is it kind of unnecessary to have an external js doc with a single function? yes
// is it useful for learning purposes? yes
function calculate() {
var tuition = document.getElementById("tuition").value;
var credits = document.getElementById("credits").value;
var classCredits = document.getElementById("classCredits").value;
var timesPerWeek = document.getElementById("timesPerWeek").value;
if (tuition && credits && classCredits && timesPerWeek) {
var moneyWasted = tuition / credits * classCredits / (timesPerWeek * 14);
moneyWasted = Number(Math.round(moneyWasted+'e'+2)+'e-'+2);
document.getElementById("results").innerHTML = "Assuming a 14 week semester, you are wasting $" + moneyWasted + " per class you skip.";
} else {
document.getElementById("results").innerHTML = "Please be sure to enter a valid value in all fields.";
}
}