{"size": 1766, "ext": "js", "max_stars_repo_path": "src/super-galactic-age-calculator.js", "max_stars_repo_name": "jieunkang-101/super-galactic-age-calculator", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/super-galactic-age-calculator.js", "max_issues_repo_name": "jieunkang-101/super-galactic-age-calculator", "max_issues_repo_issues_event_min_datetime": "2021-05-11T02:36:38.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-26T23:22:04.000Z", "max_forks_repo_path": "src/super-galactic-age-calculator.js", "max_forks_repo_name": "jieunkang-101/super-galactic-age-calculator", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 4, "max_forks_count": null, "avg_line_length": 22.3544303797, "max_line_length": 78, "alphanum_fraction": 0.5798414496}
const LIFE_EXPECTANCY_VALUE = 72;

export class AgeCalculator {
  constructor(age, region) {
    this.age = age || 0;
    this.region = region;
  }

  //to calculate galactic years
  mercuryAge() {
    const userAge = Math.round(this.age / 0.24);
    return userAge;
  }

  venusAge() {
    const userAge = Math.round(this.age / 0.62);
    return userAge;
  }

  marsAge() {
    const userAge = Math.round(this.age / 1.88);
    return userAge;
  }

  jupiterAge() {
    const userAge = Math.round(this.age / 11.86);
    return userAge;
  }

  //to calculate the life expectancy by first condition(age)
  lifeExpectancyAtBirth() {
    let expectedAgeBirth = 0;

    if (this.age >= 100) {
      expectedAgeBirth = 50;
    } else {
      for (var i = 0; i < 10; i++) {
        if (this.age >= i*10 && this.age < (i+1) * 10) {
          expectedAgeBirth = LIFE_EXPECTANCY_VALUE - (i * 2);
          
          return expectedAgeBirth;
        }
      }
    }
    
    return expectedAgeBirth;
  }

  //to calculate the final life expectancy 
  lifeExpectancyByRegoin() {
    let expectedAge = this.lifeExpectancyAtBirth(this.age);
 
    if(this.region === "NA" || this.region === "EU" || this.region === "OC") {
      expectedAge += 5;
    } else if(this.region === "LA") {
      expectedAge += 3;
    } else if(this.region === "AS") {
       expectedAge += 1;
    } else {
      expectedAge -= 5;
    }
    
    return expectedAge;
  }

  //to calculate the how many years left of surpassed the life expectany
  lifeExpectancy() {
    let expectedAge = this.lifeExpectancyByRegoin();
    let result = 0;

    if (this.age <= expectedAge) {
      result = expectedAge - this.age;
    } else {
      result = this.age - expectedAge;
    }
    
    return result;
  }  
}