Java Script Fundamentals Exercises

Hi all!

I’m doing the exercises of the Js Fundamentals, and I found that sometimes my functions are correct (they give the proper answers when I tried them out) but I don’t pass the exercise.

For example, this exercise of the Imaginary friends:

The first function is the correct solution, below is mine. Why is it wrong? It gives always the correct number…

Hello! Could you please send the link to the exercise?

There could be something to do with the way floats have rounding errors-maybe the lesson is trying to teach you to be precise, or something like that.

Yes sure!

That was my first thought…but if you have to use Math.round I thought it would be easier to just /3 instead of * 0.33


If you click on the folder icon in the upper left corner of the code editor, you can select the test.js file, and see what values are being tested. One of the tested values is 1110. Try both of the functions from your first post with that value, and you’ll see the difference.

33% is not the same as dividing by 3. (Technically, your function (dividing by 3) is more accurate, but not what the SCT is looking for.) :wink:

Interesting read:

Edit: I suppose it would be more accurate to say that multiplying by 0.33 is not the same as dividing by 3.


I see what you mean. I didn’t knew there was a test.js folder :S


1 Like

You’re welcome!

It’s not accessible in every exercise, but it is in many.

1 Like