[英]Write a function called cube that takes a parameter n
How do I write a function called cube that takes a parameter n.如何编写一个名为 cube 的 function 接受参数 n。 The function should multiply n times n times n (“cubing” n, or n to the 3rd power, mathematically speaking). function 应该乘以 n 乘以 n 乘以 n(从数学上讲,“立方”n,或 n 的 3 次方)。 The result of that multiplication should be returned at the end of the function (so that if this function was called, the answer for “n cubed” would be returned to the part of the program that called the function)该乘法的结果应在 function 的末尾返回(这样,如果调用此 function,“n 立方”的答案将返回到调用该函数的程序部分)
Simply:简单地:
function cube(n) {
return n * n * n;
}
Just wondering why you need to write this function at all?只是想知道为什么你需要编写这个函数? Just use regular javascript syntax.只需使用常规的 javascript 语法。
const cubed = n**3
Or for older syntax, the actual function already exists on Math
或者对于较旧的语法,实际的函数已经存在于Math
const cubed = Math.pow(n, 3)
Extremely simple function:极其简单的功能:
function cube(n) {
return cube ** 3;
}
Write a function cube(n) that takes a number, n, and cubes it and returns a string in the form Cube of (n) is (n cubed).编写一个 function cube(n),它接受一个数字 n 并对其进行立方,并以 Cube of (n) is (n cubed) 的形式返回一个字符串。 For example, cube(4) returns Cube of 4 is 64.例如,cube(4) 返回 4 的立方体是 64。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.