我正在开发这个简单的应用程序,它应该一次执行一个函数。这段代码是在nodejs的帮助下用javascript编写的。
我的目标是让函数1首先显示输出,然后只有函数2显示输出,但这两个函数都必须与一个大函数一起运行。
这是我的代码。
function combine(Human,Alien)
{
function one (Human)
{
TotalOne = Human + 5;
console.log(`The Number Of Human : ${TotalOne}`);
return TotalOne;
}
function two (Alien)
{
TotalTwo = Alien + 10;
console.log(`The Number Of Alien : ${TotalTwo}`);
return TotalTwo;
}
}
combine(1,3);输出似乎没有读取大函数中的函数。对如何解决这个问题有什么想法吗?
谢谢:)
发布于 2019-03-06 15:45:26
您忘记了调用内部函数。试试这个:
function combine(Human,Alien)
{
function one (Human)
{
TotalOne = Human + 5;
console.log(`The Number Of Human : ${TotalOne}`);
return TotalOne;
}
function two (Alien)
{
TotalTwo = Alien + 10;
console.log(`The Number Of Alien : ${TotalTwo}`);
return TotalTwo;
}
one(Human);
two(Alien);
}
combine(1,3);发布于 2019-03-06 15:45:29
您没有在组合函数中调用函数一和函数二
function combine(Human,Alien)
{
function one (Human)
{
TotalOne = Human + 5;
console.log(`The Number Of Human : ${TotalOne}`);
return TotalOne;
}
function two (Alien)
{
TotalTwo = Alien + 10;
console.log(`The Number Of Alien : ${TotalTwo}`);
return TotalTwo;
}
one(Human); //you missed the function invocation of one function
two(Alien); //you missed the function invocation of two function
}
combine(1,3)
发布于 2019-03-06 15:46:58
你有一个大函数和两个函数。这些是函数声明。最后一行是函数调用。此调用执行大函数,该函数在其主体中声明了两个内部函数。但是你忘了在大函数体中调用,这些函数。
https://stackoverflow.com/questions/55017918
复制相似问题