Improper usage of .ceil() not hinted in lesson or documentation?


#1

The lesson I’m on.

The code I typed:

console.log(Math.floor(Math.random() * 100));
console.log(43.8.ceil());

I’m not exactly sure of what I’m doing wrong here, and there isn’t a given example in the hint or in the JS documentation. I’d really appreciate a reply to this as soon as possible.

Thanks in advance for taking the time to read (and possibly reply to) my post!

Edited below:

Sorry, I fixed this myself… I realized you had to do Math.ceil(43.8) to fix it. I was thinking strangely due to my tired brain, as it’s pretty late at night right now. It’d be much appreciated if this topic was closed.


#2

In a course as brief as this, the author is forced to a narrower focus and a general aire of presumption. This segment of the course discusses built in math functions, all of them stored tidily in the special Math object. The presumption here is that the student will intuitively follow the same pattern,

Math.method()

The Math object consists of a range of constants and functions, which are its object attributes, something you will learn more about later on. It is still only a single entity.

The code you were experimenting with, 43.8.ceil() might well have worked if ceil was a method in the Number.prototype, though we would need to parenthesize the number.

(43.8).ceil()

A quick search of the MDN docs shows us the methods in the Number,prototype which includes the ones we see most often,

(43.8).toFixed(2)

(43.8).toString()

As we can see there are no math functions in that list as they have beem abstracted away to the Math object for safety and easy access.

Bottom line, the author presumed the user would take heed of the example given and due to limited space and time, forego explaining variants to avoid.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.