Javascript计数器功能 [英] Javascript Counter Function

查看:68
本文介绍了Javascript计数器功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个名为''count''的JS函数,它将接受两个整数参数,然后返回一个字符串,列出两个参数之间的所有数字。例如,如果我调用count(0,10),那么程序应该显示0,1,2,3等,最后是10.但是,经过大量的尝试,我只成功显示了第二个参数(10)。任何指导将不胜感激。

函数计数(num1,num2)
{

var strCou ='''';
for(count = num1; count< = num2; count ++)
{
strCou = count;
}

console.log(strCou);
}
count(0,10);

解决方案

函数计数(num1,num2)
{

var strCou = ' ';
for (count = num1; count < = num2; count ++)
{
strCou + = count;
}

console.log(strCou);
}
count( 0 10 );


I am trying to write a JS function called ''count'' which will accept two integer parameters and then return a string listing all of the numbers between the two parameters. For example, if I called count(0,10) then the program should display 0,1,2,3 etc and finally 10. However, after extensive trying, I have only succeeded in displaying the second parameter (10). Any guideance would be appreciated.

function count(num1, num2)
{

  var strCou = '''';
  for(count = num1; count <= num2; count++)
  {
    strCou = count;
  }

  console.log(strCou);
}
count(0,10);

解决方案

function count(num1, num2)
{

  var strCou = '';
  for(count = num1; count <= num2; count++)
  {
    strCou += count;
  }

  console.log(strCou);
}
count(0,10);


这篇关于Javascript计数器功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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