Skip to content
← Back to Community
Cube a number Javascript
Profile icon
MDemery

Write a function called "cube".

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

Can someone explain this to me please

Voters
Profile icon
C3s963051
Profile icon
MDemery
Comments
hotnewtop
Profile icon
vedprad1

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!

Profile icon
MDemery

@vedprad1
thanks gthat works but I used

return Math.pow(num, 3);

but your way works as well

Profile icon
vedprad1

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!

Profile icon
MDemery

@vedprad1
nah it didn't answer the question

Profile icon
ash15khng

@MDemery
How did it not??

Profile icon
MDemery

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