简体   繁体   English

你能帮我我想打印阶乘 4 的值但是下面的函数总是给 NAN 为什么?

[英]Can you help me I want to print the value of factorial 4 but the following function is always giving NAN why?

My question is about recursive function why it is showing always NAN instead of showing the value of factorial 4.我的问题是关于递归函数,为什么它总是显示 NAN 而不是显示阶乘 4 的值。

function factorial(i){
              if (i == 1) { return;}  
              return i * factorial(--i);};        
      console.log(factorial(4));
function factorial(i){
              if (i == 1) { return 1;}  
              return i * factorial(--i);};        
      console.log(factorial(4));

if (i == 1) { return;} you should return number hear like return 1; if (i == 1) { return;} 你应该返回 number 听到 return 1;

function factorial(i){
              if (i == 1) { return 1;}  
              return i * factorial(--i);};        
      console.log(factorial(4));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 你能帮我这个功能吗 - can you help me with this function 为什么我的阶乘函数返回NaN? - Why is my factorial function returning NaN? 谁能帮我告诉我为什么我在函数中得到一个空值 - Can anyone help and tell me why do i get a null value in the function 你能告诉我为什么下面的 javascript 代码并不总是在下面的简单 index.html 中出现吗? - Can you please let me know why the following javascript code is not always hitting in the following simple index.html? 我想在单击跨度时找到最接近跨度的输入元素,你能帮我吗? - I want to find an input element closest a span when I click the span, can you help me? 阶乘 function 返回 NAN - Factorial function returning NAN 如果我们在循环内调用函数,则打印相同的值。 你能帮我解决这个问题吗 - Printing same value if we call function inside the loop. Can you help me to resolve this issue 当我单击“全部”h1 元素时,我想切换。textDecoration class。 你能帮我看看这个守则吗? - I want to toggle .textDecoration class when I am clicking on "ALL" h1 elements. Can you Help me with this Code? 您能解释一下阶乘函数的工作原理吗? - Can you explain how this Factorial function works? 你可以帮帮我吗。 我怎样才能使实时变化的价值? - Could you help me. How can I make real-time changing value?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM