dopt85756 2017-01-31 02:34
浏览 30
已采纳

我需要帮助编写一个小程序来从列表中随机绘制条目

I need help writing a code which randomly selects an adjustable amount of entries from a list and displays them for me. Preferably, I should be able to adjust the entries in the list aswell. So say I have a list with the numbers A through G, and I want the code to draw 7 different entries, it would show for instance "F C D A C G B". I would also like to be able to change the list from A through G to for instance words or other letters. I've tried several codes, but this is too advanced for me. I've read through several other forums and topics, but no one is able to help me. It's important to me that the design is simple, so all I want to have on my screen is a vertical list of entries, a small box to decide how many random draws to preform, and the result being displayed in a horizontal line. I'm not asking anyone to do the job for me, that would be rude, but I'm going about this the wrong way and I desperately need some guidance, because at this point I have no idea what I'm doing and everything I try turns out to be more complicated than what it needs to be.

Thanks in advance to anyone who can help me.

  • 写回答

1条回答 默认 最新

  • dsce23640 2017-01-31 03:19
    关注

    Shorter way to generate such a string using String.fromCharCode:

    for (var i = 0, letter; i < 10; i++) {
        setTimeout(function() {
            letter = String.fromCharCode(97 + Math.floor(Math.random() * 26));
            out.appendChild(document.createTextNode(letter)); // append somewhere
        }, 2000 * i);
    }
    

    An example of how this code works can be seen here.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?
  • ¥15 讲解电路图,付费求解