[HTML]初学者js最简单的随机改变背景颜色

利用改变rgb颜色的随机数(Math.random())给背景颜色赋值

从而实现对背景颜色的随机改变

<script>
function randomNumber(){
            a=Math.floor(Math.random()*10)
            b=Math.floor(Math.random()*10)
            c=Math.floor(Math.random()*10)
            d=Math.floor(Math.random()*10)
            e=Math.floor(Math.random()*10)
            f=Math.floor(Math.random()*10)
            backgroundColor="#"+a+b+c+d+e+f
            return backgroundColor
        }
</script>

return        返回值

Math.random()随机数只能取0-1之间的所有随机数

例如:

<script>
    a=Math.random()
    console.log(a)
</script>

输出结果为:

        

 

 Math.floor()向下取整

当两个函数结合起来用就能实现随机取0-9之间的所有随机整数:

Math.floor(Math.random()*10)

随机数乘以10再向下取整就能得到较为均衡的0-9之间的随机整数

在写一个方法样式改变背景颜色

<script>
    function backGroundColor(){
            document.body.style.backgroundColor=randomNumber()
        }
</script>

最后设置一个按钮调用方法backGroundColor()

注意驼峰命名法

<button type="button" onclick="backGroundColor()">点我切换背景颜色</button>

接下来看源码和效果:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <button type="button" onclick="backGroundColor()">点我切换背景颜色</button>
    <script>
        function randomNumber(){
            a=Math.floor(Math.random()*10)
            b=Math.floor(Math.random()*10)
            c=Math.floor(Math.random()*10)
            d=Math.floor(Math.random()*10)
            e=Math.floor(Math.random()*10)
            f=Math.floor(Math.random()*10)
            backgroundColor="#"+a+b+c+d+e+f
            return backgroundColor
        }
        function backGroundColor(){
            document.body.style.backgroundColor=randomNumber()
        }
    </script>  
</body>
</html>

效果如下:

  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
随机森林是一种强大的机器学习算法,但是对于初学者来说,调参可能会有些困难。在调参的过程中,有几个参数是需要注意的。首先是n_estimators,它表示森林中决策树的数量。一般来说,增加n_estimators可以提高模型的性能,但是也会增加训练时间。另外一个参数是max_depth,它表示每个决策树的最大深度。通过增加max_depth,模型可以更好地拟合训练数据,但是也容易过拟合。还有一个参数是min_samples_split,它表示在进行节点分割时所需的最小样本数。增加min_samples_split可以防止过拟合。 此外,还有其他一些参数也需要注意,比如min_samples_leaf、max_features等。如果你是初学者,建议先使用默认参数进行训练,并通过交叉验证来评估模型的性能。然后,可以尝试调整一些关键参数,比如n_estimators和max_depth,观察模型的性能是否有所提升。 总结起来,对于初学者来说,调参是一个需要实践和尝试的过程。通过不断地调整参数并评估模型性能,你可以逐步提高对随机森林算法的理解和应用能力。可以参考中的HTML实例网页代码,通过从头开始设计个人网站并将其转换为代码的过程来实践和学习。<span class="em">1</span> #### 引用[.reference_title] - *1* [网页设计作业成品文档(HTML+CSS+JS).docx](https://download.csdn.net/download/arthas777/88240442)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序猿_小以

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值