Hello WEB ! 不是吧阿sir,JS叫智能家居!?(四)--MATH对象、函数和定时器

网盘资料链接:https://pan.baidu.com/s/1qFRLUOS-d3Ns3_avzXRrhw 
提取码:echo

  Math对象       

        开方                    Math.sqrt(x)
        绝对值                Math.abs(x)
        Π                         Math.PI
        X的y次方           Math.pow(x,y)
        取整                    Math.round(x)
        向下                    Math.floor(x)
        向上                    Math.ceil(x)
        最大数                Math.max(x1,x2,x3,x4)
        最小数                Math.min(x1,x2,x3,x4)
        随机数                Math.random() //0~1        👉      Math.random()*10 //0~10
        日期对象
                获取年                    getFullYear
                获取月                    getMonth
                获取日                    getDate
                获取周几                getDay
                获取小时                getHours
                获取分钟                getMinutes
               获取秒数                 getSeconds
                时间戳                    Date.now


    函数
        什么是函数
            函数是通常是把一系列重复使用的操作封装成一个方法,方便调用
        定义一个函数
            function  funName(){}


    函数分类及传参返回
            ①有名函数
            ②匿名函数
            ③自定义函数
                    自调用函数
                        ~function (){}
                        !function (){}
                        +function(){}
                        -function(){}
                        效果都是自己调用自己,没有区别
            ④函数传参
                    定义数量参数、不定长参数
            ⑤返回值
                    JS的作用域
                        因为 JS 的规则是先定义,然后执行所以,要写代码的时候要注意这点
                        子作用域会修改父作用域的值
                        函数外部,变量不管是否用了var声明,都是全局变量


    定时器
        ①设置/清除定时器
            setTimeout
                只在指定时间后执行一次,等再次打开网页,刷新网页才会再执行一次
            clearTimeout


        ②设置/清除定时器
            setInterval
                以指定的时间周期,循环执行,不需要重新打开网页,只有当你清楚才会停止
            clearInterval

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>4.JavaScript(三)</title>
</head>
<body>



<!--**************************************************Math对象**********************************-->
<!--<script>-->
    <!--console.log(Math.sqrt(10));-->
    <!--console.log(Math.abs(-5));-->
    <!--console.log(Math.PI);-->
    <!--console.log(Math.pow(2,5));-->
    <!--console.log(Math.round(25.465));-->
    <!--console.log(Math.floor(1.4));-->
    <!--console.log(Math.ceil(2.6));-->
<!--</script>-->
<!--在思维导图里面还有很多方法-->

<!--*************************************************日期对象**********************************-->

<!--<p id="p1"> </p>-->

<!--<script>-->
    <!--var  today = new Date();-->
    <!--var moth = today.getMonth();-->
    <!--var day = today.getDay();-->
    <!--var year = today.getFullYear();-->

    <!--var a  = document.getElementById('p1');-->
    <!--// a.innerText = moth;-->
    <!--console.log('这个月是'+moth+'月');-->
    <!--console.log('今天是星期'+day);-->
    <!--console.log('今年是'+year+'年');-->

<!--</script>-->

<!--更多操作在思维导图-->



<!--*************************************************函数**********************************-->
<p id="p2"> 滴滴答答  噢吼!!!</p>

<script>
// 有名函数------------------------------------
    function add(){
        alert(123);
    }
    // add();

// 匿名函数------------------------------------
    var  p2 = document.getElementById('p2');
    p2.onclick = function () { console.log(123) };

// 函数传参------------------------------------
        function writep(x) {
            console.log(x)
        }
    //     writep('峡谷第一厨神');

// 返回值--------------------------------------
    function f() {
        console.log(1);
        return 1;
    }
    // alert(f());

    // 不定长参数
    function bdc() {
        console.log(arguments);
        document.write('我是不定长传参!');
        for(a=0;a<arguments.length;a++){
            document.write(arguments[a]+'<br>');
        }
    }
    // bdc(1,2,3,4,'1235');

    // 自定义函数
    ~function () {
        console.log('我是自定义函数,我自动调用');
    }
    // ();


<!--*************************************************定时器**********************************-->
    // 设置/清除定时器①
    var a = setTimeout(function () {
        console.log('只在指定时间后执行一次,等再次打开网页,刷新网页才会再执行一次');
        clearTimeout(a);
    },3000);


    // 设置/清除定时器②
    var b = setInterval(function () {
        console.log('以指定的时间周期,循环执行,不需要重新打开网页,只有当你清楚才会停止');
        clearInterval(b);
    },4000);


</script>




</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Padaz

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

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

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

打赏作者

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

抵扣说明:

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

余额充值