Wednesday, March 22, 2023

Coding Challenge #29 Salary Calculator

 // a simple module to provide quick calculations to figure out hourly/monthly/yearly income rates when given one of them.
function salaryCalculator(){
    this.cash = 0;
    // 40 hour week * 52 weeks per year = 2080
    this.setHourly = function(c){
        this.cash = this.get2Decis(c * 2080);
    }
    this.setYearly = function(c){
        this.cash = c;
    }
    this.setMonthly = function(c){
        this.cash = this.get2Decis(c * 12);
    }
    this.getHourly = function(){
        return this.get2Decis(this.cash / 2080);
    }
    this.getYearly = function(){
        return this.cash;
    }
    this.getMonthly = function(){
        return this.get2Decis(this.cash / 12);
    }
    this.get2Decis = function(n){
        return Math.floor(n * 100) / 100;
    }
}

var n = new salaryCalculator();
n.setHourly(12);
console.log("Current minimum wage of " + n.getHourly() + "/hr is " + n.getMonthly() + " per month, and " + n.getYearly() + " per year.");

No comments:

Post a Comment

Coding Challenge #54 C++ int to std::string (no stringstream or to_string())

Gets a string from an integer (ejemplo gratis: 123 -> "123") Wanted to come up with my own function for this like 10 years ago ...