0
Help with adding methods.
function main() { //get the initial amount and the interest percentage var amount = parseInt(readLine(),10); var yearPercent = parseInt(readLine(),10); var loan1 = new Loan(amount, yearPercent); //output to console console.log(loan1.yearIncome(yearPercent)); } function Loan(amount, percent) { this.amount = amount; this.yearPercent = percent; this.interestPercentage = annualincome; this.yearincome = calcYearIncome; }; function loan1.calcYearIncome() { amount = loan1.yearPercent //complete the function to calculate yearly income }
8 Answers
+ 1
Emmanuel Riano It's a link to the tutorial on how to do exactly what you're asking about and shows with examples where you went wrong. Compare your code to the code in the example and read the lesson.
+ 1
https://www.sololearn.com/learn/JavaScript/1154/ Sadly that gives me a 404 error
+ 1
Owain
Are you using the app or browser. It is working fine for me via the app, but may not be available via the browser.
+ 1
Here is my answer:
function main() {
//get the initial amount and the interest percentage
var amount = parseInt(readLine(),10);
var yearPercent = parseInt(readLine(),10);
var loan1 = new Loan(amount, yearPercent);
//output to console
console.log(loan1.yearIncome (amount, yearPercent));
}
function Loan(amount, percent) {
this.amount = amount;
this.yearPercent = percent;
this.yearIncome = calcYearIncome;
//your code goes here
};
function calcYearIncome(amount, yearPercent){
//complete the function to calculate yearly income
let a = yearPercent / 100;
let b = a * amount;
return b;
};
0
Thats just a link to adding methods.
0
I figured it out took a minute not gonna lie. Thanks for not givin the answer chaoticdawg.
0
Thank you ChaoticDawg. The problem for me is that the task is a lot more complex than the examples in the tutorial from a learner's point of view. Having said that, it is slowly starting to make sense....