01
<!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 getProduct() {
let product=1
for(let i=0;i<arguments.length;i++){
product*=arguments[i]
}
return product
}
document.write(getProduct(1,2,3,4,5))
</script>
</body>
</html>
——————————————————————————————————————————————————
02
<!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>
for(let i=0;i<=100;i++){
if(i%10==7||i%7==0){
document.write(` ${i}`)
}
}
</script>
</body>
</html>
——————————————————————————————————————————————————
03
<!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 rabbitNumber(n) {
if (n < 4) {
return 1;
}
return rabbitNumber(n-1) + rabbitNumber(n-3);
}
document.write(rabbitNumber(5));
</script>
</body>
</html>
笔记
获取当前时间对应的时间对象
let date = new Date("2024-01-01 0:0:0")
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()
let ms = date.getMilliseconds()
时间戳:1970-1-1 0:0:0到当前时间对象的毫秒数
let ttt = date.getTime()
18:21:33 2023-12-6
document.write(`${hour}:${min}:${ss} ${year}-${month}-${day} 星期${week} `)
console.log(ttt)
_____________________________________________________________________________
1、'' "" ``
2、String
let str = new String("zhangsan")
console.log(typeof (str))
let str1 = String("cjdncd")
length
console.log(str1.length)
_____________________________________________________________________________
1、获取下标对应的字符
console.log(str.charAt(4))
2、
console.log(str.indexOf("a"))
console.log(str.lastIndexOf("a"))
console.log(str.indexOf("a"))
let str1 = "nanhang"
let str2 = "jincheng"
let str3 = str1.concat(str2)
console.log(str3)
使用正则匹配想要的内容
let a = str.match(/\d/g)
console.log(a)
使用正则替换
alert(str.replace(/a/g, "---------"))
console.log(str.slice(2, 4))
split("")按照特定的符号分割字符串
let str4 = "nanhang jincheng"
console.log(str4.split(""))
let b1 = str4.split("")
join()
console.log(b1.join(""))
console.log(str.toUpperCase())
console.log(str.toLowerCase())
_____________________________________________________________________________
Number()
parseInt()
parseFloat()
getSum(1, 2)
函数就是一段具有独立功能的代码的集合
/**
* function 函数名(参数){
* 代码块
* }
*
*/
getSum(1, 2)
函数提升
function getSum(num1, num2) {
let a = 1
let b = 2
alert(num1 + num2)
console.log("函数调用了")
return num1 + num2
}
函数名()
let a = getSum(3, 4)
console.log(a)
getSum()
_____________________________________________________________________________