Ask coding questions

← Back to all posts
1
Cube a number Javascript
MDemery (0)

Write a function called "cube".

Given a number, "cube" returns the cube of that number.

Can someone explain this to me please

Commentshotnewtop
1
vedprad1 (433)

If you want the answer, it is here:

function cube(n) {
  return n * n * n;
}

If this answers your question, please check the checkmark on the left side of this message. Thanks and Good Luck!

1
MDemery (0)

@vedprad1 thanks gthat works but I used

return Math.pow(num, 3);

but your way works as well

1
vedprad1 (433)

This is simple mathematics. If you have a number, the cube of the number is that number multiplied by itself 3 times. In other words, the cube of n is n * n * n, or n^3.

If this answers your question, please check the checkmark on the left side of this message. Thanks and Good Luck!

1
MDemery (0)

@vedprad1 nah it didn't answer the question

1
MDemery (0)

@ash15khng the way he explained it confused me once seen in the function I understood what he was trying to explain.