有多少人适合这个数字?

bil*_*een 4

我是Javascript的新手.

我想知道每个数字中有多少数字.所以894等于8. 323等于3.

这是我写的代码,你可以猜到它不起作用.

function howManyHundreds(num) {
  return num / 100;
  return num % 10;
}

console.log(howManyHundreds(894))

console.log(howManyHundreds(323))
Run Code Online (Sandbox Code Playgroud)

894将打印到8.94,323将打印为3.23

我做错了什么,我需要知道什么?我使用模数运算符错了吗?

谢谢您的帮助.

Nis*_*arg 5

您想用来Math.floor获取除法的整数分量.您可以在下面的代码段中看到更新的代码:

function howManyHundreds (num) {
  var division = num / 100;
  return Math.floor(division);
}

console.log(howManyHundreds(894));
console.log(howManyHundreds(323));
Run Code Online (Sandbox Code Playgroud)

注意:请记住,这不会像您期望的那样使用负数.如果需要,可以使用Math.abs获取绝对值然后得到结果.