zilongxuan001 / LearnFreecode

0 stars 0 forks source link

Generate Random Whole Numbers with JavaScript #268

Open zilongxuan001 opened 6 years ago

zilongxuan001 commented 6 years ago

介绍

生成0到任意区间的随意整数。

方法

Math.floor(Math.random() *20)

生成0到20之间的整数,不包括0和20。

练习

Use this technique to generate and return a random whole number between 0 and 9.

代码


var randomNumberBetween0and19 = Math.floor(Math.random() * 20);

function randomWholeNum() {

  // Only change code below this line.

  return Math.floor(Math.random()*10);
}

结果显示

image

来源

https://www.freecodecamp.org/challenges/generate-random-whole-numbers-with-javascript