FAQ: Introduction to JavaScript - Arithmetic Operators

This community-built FAQ covers the “Arithmetic Operators” exercise from the lesson "Introduction to JavaScript ".

Paths and Courses
This exercise can be found in the following Codecademy content:

Web Development

Introduction To JavaScript

FAQs on the exercise Arithmetic Operators

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

3 posts were split to a new topic: What is the difference between printing 3 + 4 and '3 + 4'?

Kind of a funny lesson =)


7 posts were split to a new topic: How does Javascript handle a negative modulo? (-5 % 20)

why is it when i do ‘‘console.log(240/65)’’. it says ‘‘Did you divide 65?’’


Are you sure of your understanding of divide 65 by 240?


yeah i do understand

So have you sorted out your question, then?

Do I need to put spaces between the symbols in parentheses or it’s ok to go without them? like “console.log(3 + 4)” or “console.log(3+4)”

1 Like

Welcome, @py9568079721.

No, spaces are not needed; however, keeping white space around operators lets them stand out and makes readability and debugging much easier so it is recommended.

y = m * x + b

as opposed to,


Idk why im even paying for this site…

var age = 21;
console.log(age + 3.5);

Results in the Console logging 24.5

Still i the Result doesnt count and i need to go to baby level ???
console.log(21 + 3.5);

Did the instructions ask us to create a variable for our age? Seems the author meant for us to literally write it into the console.log() statement.

P. S. Griping is not going to win you much support. Pull up your socks and invest yourself. Forget about the money. The real investment is your attitude and effort.

“/” is the JavaScript way to divide

Why does the remainder of console.log(5%20) = 5 and not 0?

Might want to recheck your math, there. 5 % 21 is 5. 21 % 5 is 1.

Can you use the remainder operator when using decimal numbers?

Yes, we can, though we need to be able to interpret the outcomes. Bear in mind that floating point math is not the same as integer math so we likely won’t see 0 as the result even if a number is divisible.


console.log(2.25 % 0.15)    //  8.326672684688674e-17

Compare this to,

console.log(225 % 15)    //  0

The simplest use case is where the divisor is unity (1).

console.log(3.14 % 1)    //  0.14000000000000012

Note again the floating point arithmetic error. We have very nearly extracted the decimal portion of the dividend though we have to mitigate the error to arrive at the actual value, 0.14.

As a predicate to determine if a value is float or not,

if (n % 1 === 0) {
    // n is an integer or very nearly one; 3.0 => 3
} else {
    // n is a float
1 Like

Thank you! So in a simple sense, a float number doesn’t compute properly through the remainder operator?

1 Like

In as much as we have to contend with the arithmetic error, no; it is much better suited to integer division.

1 Like

@ mtf good note on spaces between the input. did not think about debugging

1 Like