<!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>
let sum = 0;
for(var i = 0;i<101;i++){
console.log(i);
if(i%7 == 0 || i%10 == 7){
sum = sum + i;
}
}
console.log(sum);
</script>
</body>
</html>
<!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 fn(){
let a=1
for (let i=0;i<arguments.length;i++){
a*=arguments[i]
}
return a
}
console.log(fn(,))
</script>
</body>
</html>
<!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 rabbit(n) {
if(n < 4){
return 1;
}
return rabbit(n-1) + rabbit(n-3);
}
</script>
</body>
</html>
date
获取当前时间对应的时间对象
let date = new Date("")
console.log(timer)
年
let year = date.getFullYear()
月
let month = (date.getMonth() + 1) < 10 ? "0" + (date.getMonth() + 1) : (date.getMonth() + 1)
日
let day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate()
时
let hour = date.getHours()
分
let min = date.getMinutes()
秒
let ss = date.getSeconds()
星期
let week = date.getDay()
字符串对象
String
let str = new String("zhangsan")
console.log(typeof (str))
let str1 = String("cjdncd")
length
console.log(str1.length)
函数
函数就是一段具有独立功能的代码的集合
function 函数名(参数){
代码块
}
getSum(1, 2)
函数提升
function getSum(num1, num2) {
console.log("")
return num1 + num2
}
函数名()
let a = getSum(3, 4)
console.log(a)
作用域:名字生效的范围 全局作用域、函数作用域
let a = 1
function a1() {
console.log(a)
let num = 11
}
a1()
console.log(num)
函数作为参数进行传递
function a() {
console.log("a")
}
function b(fn) {
fn()
console.log("b")
}
b(a)
默认值参数
默认值参数放在所有参数的最后面
function a(r, PI = 3.14) {
alert(PI * r * r)
}
a(3)
匿名函数
// 函数的表达式
let a = function () {
console.log(666)
}
a()
箭头函数
let a = function (a) { alert("hello") }
let a = () => alert("hello")
a()
递归
unction jieCheng(n) {
if (n === 1) {
return 1
} else {
return jieCheng(n - 1) * n
}
}
console.log(jieCheng(3))