Ad
  • Default User Avatar
  • Custom User Avatar

    I think to not have it available is the point of this kata.

  • Custom User Avatar

    This is caused by outdated and confusing formatting of test cases layout. Fixed in update of the tests.

  • Custom User Avatar

    It's not a good idea to just tell the answer, or you don't learn much from it. But Chrono79 told you what the problem is exactly, and I tried showing you small steps, so you could find the problem on your own ( but you didn't seem to try them :/ ).

    If you do recursion, and use console.log in it, you will get the answer in console, but nothing will be returned to you from the initial function call, so you get undefined as the final answer. CodeWars tests work with returned values, and not output from console.

    It doesn't mean you can't use console.log, but you should understand that your code doesn't stop on that line. That's why I suggest looking at recursion online, compare with your code, and see if something is missing.

  • Custom User Avatar

    Well, it's your choice to believe in some fairytales, and not the truth. However, don't be surprised to see the same thing when you do another kata involving recursion :P As a popular phrase goes: "you can lead a horse to water, but you can't make it drink"

  • Custom User Avatar

    having console.log shouldn't be a problem anyhow

    Actually, that's the entire problem... And if you don't think it is, why is your solution not accepted?

  • Custom User Avatar

    js shows undefined return in codepen works ok

    That's because you don't understand the difference between console.log and return.

    Please read this: https://docs.codewars.com/training/troubleshooting/#expected-the-same

  • Custom User Avatar

    You still have console.logs in your solution. There shouldn't be any. And from what I see the problem is the same, your recursion is wrong.

  • Custom User Avatar

    No it doesn't work. It only 'works' because you use console.log to ouput the value. Try changing the last line to console.log(persistance(999)) and remove every single console.log inside your function. See if that changes the output.

    As as extra hint, get rid of the global variable (first line) and move it inside function, or you will get unpredictable results. Also, look up how recursion should be done correctly.

  • Custom User Avatar

    If this is an exact excerpt from the log, then you are probably misinterpreting it.

    Please see if this paragraph helps: https://docs.codewars.com/training/troubleshooting#print-input

  • Custom User Avatar

    Language?

  • Custom User Avatar

    It's not. Why do you think it is?