繁体   English   中英

如何在一个维数组中存储3个随机数,然后在Javascript中得到警告

[英]How to store 3 random numbers in a single dimensional array and then get alerted in Javascript

function next_question()
{


for (i = 0; i <= 2 ; i++)
{
    a = Math.floor(Math.random() * (8 - 0)) + 0;
ques_number[i] = a;

}

alert (ques_number[0]);


}

我想创建一个数组,其中有3个随机数,然后获得有关哪些数字存储在数组中的警报! 看起来很简单,但由于上述代码无法正常工作,我在这里所做的基本上是错误的! 请帮忙谢谢

你需要

  • 全局变量ques_number
  • 两个局部变量ia
  • 简化的随机部分

 var ques_number = []; function next_question() { var i, a; for (i = 0; i <= 2 ; i++) { a = Math.floor(Math.random() * 8); ques_number[i] = a; } alert(ques_number[0]); } next_question(); document.write('<pre>' + JSON.stringify(ques_number, 0, 4) + '</pre>'); 

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM