javascript 题目

来源:百度知道 编辑:UC知道 时间:2024/05/29 00:30:00
5. After a JavaScript function runs the following two lines of code, what value does the variable x contain?(5 scores)
arr = new Array(5);
x = Math.random() / arr.length;
A. a floating point number between 0.0 and 0.2
B. a floating point number between 0.0 and 0.25
C. a floating point number between 0.0 and 1.0
D. a floating point number between 0.0 and 5.0
E. x would not be assigned due to one or more errors in the code
选哪个?

选择:A

原因:
1: arr的值应该为:,,,,
2: arr.length 的值为 5
3: Math.random()的值是产生0到1之间的一个随即数
4: So: 0 < x < 0.2

我觉得应该是选择A,因为random的范围是0和1之间,除以5,得到的结果就应该是0和0.2之间

选A
Math.random()是大于0小于1的数
arr。length是5
所以。。。。。。