Day 21 Important Note! Need to round answer to 2 decimal places


It’s not mentioned in the challenge or hint, but the previous challenge in the spring hinted that the result should be rounded to 2 decimal places. Doesn’t seem to accept my code if I didn’t round.


Can confirm, need to round to 2 decimal, strings are acceptable!


Confirmed. That was the only thing I missed, thanks!!
Happy coding


Thank you, sir, for the critical hint! :kissing_heart:


Thank you for the hint!

My 21-days browser IDE was bugged where it said “too many errors”, even though there weren’t any errors when pasting the code into vscode. I thought it was some linting issue, but apparently it was just the 2 decimal places.


I think that might be a linting error (e.g. something like missing optional semi-colons) because I’ve had that message and no problem getting my code to pass.


Mine still doesn’t work, even with the two decimal places. I set up my equation just like in the distance calculator in the hint, and it still wont pass :sob::sob:


I think that might be a linting error

I think it is. I run my code in a separate compiler before pasting it in for the challenge, so I know I have every semi-colon, every bracket without error… But pasting it in the challenge is telling me I have “too many errors” without any kind of indicator as to what is missing. Oh well.


Did you try passing in 2 coordinates, e.g. ‘A3’, ‘B5’? Did you get an answer that is a number rounded to 2 decimal places?

Maybe make sure you don’t have your x and y coordinates flipped or the first and second positions in the wrong place?


Yeah it could even be something opinionated but not an error like spaces instead of tabs or vice versa. Showing that error but not the linting rules is pretty confusing. It should be safe to ignore, especially if you’re linting separately.


Yah i have 2 decimal places, and I’ve tried my coordinates both way. I THINK what the issues is (just came to me) is that it’s not taking into consideration, row values that have a double digit (C10, D11, etc), and are only grabbing the first digit (C1, D1, etc). Need to try and factor that in and see if thats the issue here.


And thats exactly what the issue was. It’s passed now.


I’m totally lost on this one. I’m not sure what the outcome is supposed to be. If I give the function A1 and J10. What is the answer supposed to be. There are 9 squares between them, is that the answer?


You need to use the distance formula like it says in the hint:

For the distance between A1 and J10, the actual array coordinates are [0,0] and [9,9]. If you enter those numbers into the calculator at the link above, the results is 12.727922. So your function should return that rounded to 2 decimal places, 12.73.


Thank you very much, will give it a shot. For some reason I totally forgot about the hint button.


Thanks again! Completed.


Wow - wish I read this first before banging my head for an hour! Thanks - worked like a charm. They really should have specified it in the question. All done now, thanks Lighthouse 'twas fun.


what might possibly went wrong with my code? its saying, Your code ran but did not produce the correct result.

function calcDistance(coord1, coord2){
return Math.sqrt(Math.pow((convertColumn(coord2)-convertColumn(coord1)),2)+(Math.pow(convertRow(coord2)-convertRow(coord1)),2)).toFixed(2);


I can’t see your convertColumn or convertRow functions, but if they create the same result as mine, then the only thing that is wrong is the bracketing in the return statement of calcDistance. You have a set of brackets that is causing the math to calculate in the wrong order. After the plus sign, remove that open bracket, then remove the close bracket after (coord1)

correct return statement:
return Math.sqrt(Math.pow((convertColumn(coord2)-convertColumn(coord1)),2)+Math.pow(convertRow(coord2)-convertRow(coord1),2)).toFixed(2);