zsydgithub 1 年之前
父节点
当前提交
a386ba7f69
共有 4 个文件被更改,包括 157 次插入0 次删除
  1. 63 0
      js/10_函数.html
  2. 40 0
      js/11_数组.html
  3. 11 0
      js/8_练习2.html
  4. 43 0
      js/9_循环.html

+ 63 - 0
js/10_函数.html

@@ -0,0 +1,63 @@
+<!DOCTYPE html>
+<html lang="en">
+
+<head>
+  <meta charset="UTF-8">
+  <meta http-equiv="X-UA-Compatible" content="IE=edge">
+  <meta name="viewport" content="width=device-width, initial-scale=1.0">
+  <title>Document</title>
+</head>
+
+<body>
+  <script>
+    /* 关键字  函数名(参数1,参数2) */
+    // function num(x,y){
+    //   console.log(x+y)
+    // }
+    /* 函数名(传递参数) */
+    // num(5,10)
+
+    /* js函数可以通过function关键字去进行创建 后面跟着函数名() */
+    /* 函数名可以包含数字、字母、下划线、美元符号  */
+    /* 函数名(参数1,参数2) */
+
+
+    // function name(){
+    //   console.log(222)
+    // }
+    // name()
+
+
+    /* 计算三角形面积 */
+    /* function area() {
+      var a = window.prompt('请输入三角形底边长度')
+      var b = window.prompt('请输入三角形高度')
+      var c = a * b / 2
+      alert('三角形面试为' + c)
+    }
+    area() */
+
+
+    /* var a = 111 //全局变量
+    function num(){
+      console.log(a)
+      var b = 222 //局部变量
+      console.log(b)
+    }
+    num()
+    console.log(b) */
+
+    /* 局部变量只能在局部访问 全局变量可以在任何地方访问 */
+
+    var a = 1
+    function num() {
+      console.log(a)
+      a = 3
+      console.log(a)
+    }
+    console.log(a)
+    num()
+  </script>
+</body>
+
+</html>

+ 40 - 0
js/11_数组.html

@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<html lang="en">
+
+<head>
+  <meta charset="UTF-8">
+  <meta http-equiv="X-UA-Compatible" content="IE=edge">
+  <meta name="viewport" content="width=device-width, initial-scale=1.0">
+  <title>Document</title>
+</head>
+
+<body>
+  <script>
+    var a = [1, 2, 3, 4, 5] // 数组里面包括索引 值 长度 array
+    var b = 1
+
+    var c = ['hahhah', 111, '123n']
+    console.log(c)
+    /* 数组里面 可以存放任何值 */
+
+    var d = new Array()
+    d[0] = 11
+    d[1] = 'xixi'
+    d[4] = 'hahah'
+    console.log(d)
+    //empty 空占位符
+    console.log(d[6])
+
+    // var f = [666, 777]
+    // d[2] = f[0]
+    // d[3] = f[1]
+    // console.log(d)
+
+
+    for (var i = 0; i < d.length; i++) {
+      console.log(d[i])
+    }
+  </script>
+</body>
+
+</html>

+ 11 - 0
js/8_练习2.html

@@ -1,17 +1,28 @@
 <!DOCTYPE html>
 <html lang="en">
+
 <head>
   <meta charset="UTF-8">
   <meta http-equiv="X-UA-Compatible" content="IE=edge">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <title>Document</title>
 </head>
+
 <body>
   <script>
     /* 
     输入年份 判断是否是闰年  如果是 输出为 当前年份为闰年  如果不是 输出 当前年份不是闰年
     年份是4的倍数  且 不是100的倍数
     */
+
+    var a = window.prompt('请输入年份', 2023)
+
+    if (a % 4 == 0 && a % 100 != 0) {
+      alert('我是闰年')
+    } else {
+      alert('我不是闰年')
+    }
   </script>
 </body>
+
 </html>

+ 43 - 0
js/9_循环.html

@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<html lang="en">
+
+<head>
+  <meta charset="UTF-8">
+  <meta http-equiv="X-UA-Compatible" content="IE=edge">
+  <meta name="viewport" content="width=device-width, initial-scale=1.0">
+  <title>Document</title>
+</head>
+
+<body>
+  <script>
+    /* 循环的书写格式 */
+    // for (var i = 0; i < 10; i++) {
+    //   console.log('i当前的值为' + i)
+    // }
+
+    // for (var i = 0; i < 10; i++) {
+    //   console.log('i=' + i)
+    //   for (var j = 0; j < 10; j++) {
+    //     console.log('j当前的值' + j)
+    //   }
+    // }
+
+    // var a = 1
+    // while(true){
+    //   console.log(111)
+    // }
+
+    /* 无论条件是否成立  都执行一次do里面的语句 */
+    do {
+      console.log(222)
+    } while (false)
+
+    var a = 13
+    for (var i = 0; i < a; i++) {
+      console.log(i)
+    }
+
+  </script>
+</body>
+
+</html>