Challenge 19 questions


#1

Is it even possible to produce something like [9.00, 7.00] in JavaScript?


#2

Why is it even possible to produce something like [9.00, 7.00] in JavaScript?

I’d love to help you, but your question makes no sense. It’s like saying “Why do people wear ties?” or “How does it feel to be water?”

The answer to your question as written is that any programming language needs to perform mathematic functions, and producing numbers with fixed decimal places are simply ways to denote the accuracy of that mathematic function. But that’s just so common sense, I feel like you meant to ask a different question.


#3

Maybe he meant How is it possible?


#4

ok I guess what I meant to say is that JavaScript will just interpret [9.00, 7.00] as [9, 7] since it will ignore the trailing 0’s, but the challenge says I should have returned [9.00, 7.00], hence I asked the question. I guess it doesn’t really matter if it is 9.00, 9.0000, or just 9. :smiley:


#5

Yeah, that might have been a better wording of the question lol


#6

Maybe to give you some insight, toFixed() actually returns a string representation of the number you’re calling it on (docs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed). I would interpret this as sometimes you don’t want to output a bazillion decimals to a user or on the screen. Maybe you only need 1-3 decimals. Thus, JS allows you to format your number to whatever precision you would like. Hope that clears things up a little!


#7

Sorry about the misleading question, but I am simply saying that you can’t produce something like [9.00, 7.00] in JavaScript. That’s all.


#9

@chongtianzongwu, I agree. When I give Chrome’s JS console

[9.00, 7.00]

it gives me

[9, 7]


but when I give it the same functions as I used in ## Challenge #19, it gives

["9.00", "7.00"]

which are Strings, and yet my code solves the challenge. Can anyone confirm whether “an array of two number values” (I take that to mean values of type Number) also solves the challenge?


#10

@m_k I passed the challenge using toFixed and convert them back to number type. I am pretty sure it doesn’t matter if you use string or number type since I believe LighthouseLabs is using == for test cases. Here are some examples:

9 == '9'; // true
9 == '9.00'; // true
9.00 == '9'; // true
9.00 == '9.00'; // true
0.1 + 0.2 == 0.3; // false