fengchuanyu 4 сар өмнө
parent
commit
4419359292

+ 29 - 0
js复习/10_布尔型扩展.html

@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+</head>
+<body>
+    <script>
+        // var a = true;
+        // 如果实用数字代替布尔类型 那么数字为0时为假 其他为真
+        // var a = 1;
+        // 如果实用字符串代替布尔类型 那么空字符串为假 其他为真
+        // var a = "";
+        // undefined 为假
+        // var a;//undefined
+        // null 为假
+        // var a = null;
+        // 数组类型永远都为真
+        // var a = [];
+        var a = {};
+        if(a){
+            console.log("真");
+        }else{
+            console.log("假");
+        }
+    </script>
+</body>
+</html>

+ 37 - 0
js复习/11_对象类型.html

@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+</head>
+<body>
+    <script>
+        var person = {
+            name: "小朋",
+            age: 18,
+            sex: "男",
+            talk:function(){
+                // console.log(person.name);
+                // 在对象当中实用this 指向当前对象
+                console.log(this.name);
+            }
+        }
+
+        person.school = "黑大";
+        console.log(person);
+        // person.talk();
+        // var person2 = {
+        //     name: "小红",
+        //     age: 18,
+        //     sex: "女"
+        // }
+        // console.log(person.name);
+
+        // var arr = [person, person2];
+
+        // person.age = 20;
+        // console.log(person);
+    </script>
+</body>
+</html>

+ 46 - 0
js复习/12_函数.html

@@ -0,0 +1,46 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+</head>
+<body>
+    <script>
+        // function foo(){
+        //     console.log("hello world");
+        // }
+
+        // foo();
+
+        // function foo(str){//str 为函数参数 (形参)
+        //     console.log(str);
+        // }
+
+        // foo("hello world");//hello world 为函数实参 (实参)
+
+        // 如果多个参数,用逗号隔开
+        // function foo(a,b){
+        //     console.log(a+b);
+        // }
+        // foo(1,2)
+
+        // 函数可以返回值 实用return  但如果执行renturn后,后面的代码将不再执行
+        // function foo(a){
+        //     a = a * 1;
+        //     return a;
+        //     console.log("end");
+        // }
+        // var num = foo("123");
+        // console.log(num + 1);
+
+        // 匿名函数
+        var foo = function(){
+            console.log("hello world");
+        }
+
+        foo();
+
+    </script>
+</body>
+</html>

+ 21 - 0
js复习/13_数组的内置方法.html

@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+</head>
+<body>
+    <script>
+        var arr = [1,2,3,4,5,6];
+        // push 向数组末尾添加新值
+        arr.push(7);
+        // unshift 向数组开头添加新值
+        arr.unshift(0);
+        // pop 从数组末尾删除一个值
+        arr.pop();
+        arr.shift();
+        console.log(arr);
+    </script>
+</body>
+</html>

+ 45 - 0
js复习/练习题1_数字炸弹.html

@@ -0,0 +1,45 @@
+<!DOCTYPE html>
+<html lang="en">
+
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+</head>
+
+<body>
+    <script>
+        // 生成随机数字
+        var num = Math.random();
+        // 得到一个0-99的随机数 且 有小数部分
+        num = num * 100;
+        // 取整 0-99的整数
+        num = Math.floor(num);
+        // 获取1-100的整数
+        num = num + 1;
+
+        // 循环判断用户输入的数字是否正确
+        var flag = true;
+        // 计算游戏次数
+        var i = 0;
+        while (flag) {
+            // 接收用户输入的数字
+            var res = window.prompt("请输入一个1-100的整数");
+            // 将用户输入的内容转换为数值型
+            res = res * 1;
+            if (res == num) {
+                alert("恭喜你猜对了,一共猜了"+i+"次");
+                flag = false;
+            } else if (res > num) {
+                alert("你猜大了");
+            } else if (res < num) {
+                alert("你猜小了");
+            }
+            // 计算游戏次数
+            i++;
+        }
+
+    </script>
+</body>
+
+</html>