Ad
  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    I don't know if the tests for this are broken or if I made a mistake, but something is wrong. The code I wrote inside a different text editor works great and gives me the expected years when I checked it against the test cases. However, when I run it through the codewars editor, the tests come back undefined. Can anyone help? Here's my code:

    var years = 0;
    function calculateYears(principal, interest, tax, desired) {
    if(principal < desired){
    var interestEarned = principal * interest;
    var taxAmount = interestEarned * tax;
    var net = interestEarned - taxAmount
    principal += net;
    years ++;
    calculateYears(principal, interest, tax, desired)
    }else{
    return years
    }
    }