简体   繁体   English

写一个 function 的 cube 参数为 n

[英]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.

相关问题 编写一个valueStock函数,该函数将一组产品作为参数 - Write a valueStock function that takes an array of products as a parameter 编写一个函数来打印接受这个 wa 中的参数的总和: sum(2)(3) 并输出 5 - Write a function to print the sum which takes the parameter in this wa: sum(2)(3) and outputs 5 我需要编写一个 function,它采用华氏度的单个参数并将其转换为摄氏度 - I need to write a function that takes a single parameter in Fahrenheit and converts it to celsius 编写一个接受整数n的函数,并计算介于0到n之间的整数包含5 - Write a function that takes an integer n, and compute between 0 and n how many integers contain 5 我正在尝试编写一个函数,该函数采用 n 个整数参数并返回所有参数的乘积 - I am trying to write a function that takes n numbers of integer parameters and return the products of all the arguments 如何编写从服务器端 JavaScript 调用的 Java 方法,该方法将 JS 回调函数作为参数? - How do I write a Java method, to be called from server side JavaScript, that takes a JS callback function as an argument? 如何编写一个称为countDots(x)的函数,该函数将字符串作为参数并返回包含的点数(。)。 - How do I write a function called countDots(x) that takes a string as an argument and returns the number of dots (.) it contains 编写一个将对象数组作为参数并返回对象名称数组的函数。 然后,将该阵列记录到控制台 - write a function that takes an array of objects as a parameter and returns an array of the objects' names. then, log that array to the console 以数组为参数的JavaScript函数 - JavaScript function that takes an array as a parameter 如何绑定到以功能为参数的功能 - How to bind to function that takes function as parameter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM