Javascript-乘以2个数字并返回数字
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26496289/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Javascript- Multiplying 2 numbers and return number
提问by terry
I normally have understood this stuff well as I am taking web programming for a non-major class and guess I am just a little confused on what I'm being asked to do.
我通常已经很好地理解了这些东西,因为我正在为非专业课程学习网络编程,我想我只是对我被要求做的事情有点困惑。
I am told to "Write a function named "MULTIPLY" that accepts 2 parameters. the function will be declared this way:
我被告知“编写一个名为“MULTIPLY”的函数,它接受 2 个参数。该函数将以这种方式声明:
function MULTIPLY(parameter1, parameter2){
//The parameter names can be whatever you want
//Your code goes here
};
I have wrote this as my code :
我写了这个作为我的代码:
function MULTIPLY (price, shipping) {
return price*shipping;
enter code here
product=number1*number2;
//return the result
return total;
回答by johnalex
<script>
function multiplyNumbers(x,y){
return x*y;
}
var z= multiplyNumbers(4,5); // Function is called, return value will end up in z
</script>
<button onclick="document.getElementById('multiplication').innerHTML=z;">Multiply numbers</button>
<p id="multiplication"></p>
回答by DrRoach
You have a few problems. Here is how it should look
你有几个问题。这是它的外观
function MULTIPLY(price, shipping) {
//Return the sum
return price*shipping;
}
//Call MULTIPLY to multiply the two numbers
var product=MULTIPLY(number1, number2);

