温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

程序的基本结构

发布时间:2020-08-09 03:01:33 来源:网络 阅读:179 作者:outsider96 栏目:web开发

基本结构
顺序结构、逻辑分支结构、循环结构
对于顺序结构,就是对代码的解析是自上而下的解析;

逻辑分支结构
/单分支结构的写法
if(条件){
//statements
如果条件为true,执行,否者不执行
}
多分支
if(条件){
//statements
//条件成立时,可执行的代码
}else{
//条件不成立时,可执行代码
}

用if判断数据类型
var val = {};
var type = typeof val;
//console.log(typeof typeof val);
if(type == "number"){
console.log(val+'是数值类型');
}else if(type == "string"){

        }else if(type == "boolean"){

        }else if(type == "undefined"){

        }else{
            if(Boolean(val)){
                console.log("object");
            }else{
                console.log("null");
            }
        }

        **switch结构**
        switch(变量或者表达式){
            case 值1:
                //当表达式或者变量的值与值1相等时要执行的代码
                break;
            case 值2:
                ……
            case 值n:

            default:
                //以上的值均不匹配时,要执行的代码
        }

        案例:
        判断奇偶数
        <script type="text/javascript">
        var num = prompt("请输入一个整数");
        if(num%2==0){
            document.write(num+"是偶数");
        }else{
            document.write(num+"是奇数");
        }
    </script>

    switch结构的周几的输出
    <script type="text/javascript">
        var oDate = new Date();
        var day = oDate.getDay();

        switch(day){
            case 0:
                document.write("周日");
                break;
            case 1:
                document.write("周一");
                break;
            case 2:
                document.write("周2");
                break;
            case 3:
                document.write("周3");
                break;
            case 4:
                document.write("周4");
                break;
            case 5:
                document.write("周5");
                break;
            case 6:
                document.write("周6");
                break;
        }

    </script>
向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI