如何创建输出多个结果的函数? [英] How do I create a function that outputs multiple results?

查看:47
本文介绍了如何创建输出多个结果的函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的函数按顺序输出三个数字。它仍然只输出一个数字。我使用逗号分隔三种不同的输出,但我不确定这是否正确或如何正确使用。



我有什么试过:





函数myFunction(){

var output = calsPerDay();

var x ='蛋白质,脂肪,碳水化合物:';

var result;

if(find(mesomorph)。checked)

result =(output * .5,output * .4 ,输出* .2)

else if(find(ectomorph)。checked)

result =(输出* .7,输出* .4,输出*。 2)





document.getElementById(macros)。innerHTML = x + Math.round(result);

}

I want my function to output three numbers in order. It still is only outputting one number. I am using a comma to separate the three different outputs, but I am not sure if this is correct or how to do it properly.

What I have tried:


function myFunction() {
var output = calsPerDay();
var x = 'Protein, Fat, Carbohydrate:';
var result ;
if (find("mesomorph").checked)
result = (output*.5 , output*.4 , output*.2)
else if (find("ectomorph").checked)
result = (output*.7 , output*.4 , output*.2)


document.getElementById("macros").innerHTML = x + Math.round( result );
}

推荐答案

学习使用 JavaScript数组 [ ^ ]

这篇关于如何创建输出多个结果的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆