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 }

19th Dec 2020, 1:09 AM
Emmanuel Riano
Emmanuel Riano - avatar
8 odpowiedzi
19th Dec 2020, 2:56 AM
ChaoticDawg
ChaoticDawg - avatar
+ 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.
19th Dec 2020, 7:48 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
https://www.sololearn.com/learn/JavaScript/1154/ Sadly that gives me a 404 error
12th Mar 2021, 7:18 PM
Owain
Owain - avatar
+ 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.
12th Mar 2021, 11:16 PM
ChaoticDawg
ChaoticDawg - avatar
+ 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; };
28th Mar 2021, 1:50 PM
Leanne Smith
Leanne Smith - avatar
0
Thats just a link to adding methods.
19th Dec 2020, 6:14 AM
Emmanuel Riano
Emmanuel Riano - avatar
0
I figured it out took a minute not gonna lie. Thanks for not givin the answer chaoticdawg.
19th Dec 2020, 9:23 PM
Emmanuel Riano
Emmanuel Riano - avatar
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....
13th Mar 2021, 7:14 AM
Owain
Owain - avatar