逻辑控制语句
function print(){
const SEASON = 3
if(SEASON>=1&&SEASON<=3){
console.log('春天来了')
}else if(SEASON>=4&&SEASON<=6){
console.log('夏天来了')
}else if(SEASON>=7&&SEASON<=9){
console.log('秋天来了')
}else if(SEASON>=10&&SEASON<=12){
console.log('冬天来了')
}
}
直接从页面输出
function writeHello(){
document.write(`hello`)
}
数据类型相加
function test(){
let i = 10
let j = 1.1
let x = 'etoak'
let y = true
let z = null
document.write(`${i}+${j}=${i+j}<br>`)
document.write(`${i}+${x}=${i+x}<br>`)
document.write(`${i}+${y}=${i+y}<br>`)
document.write(`${i}+${z}=${i+z}<br>`)
document.write(`${j}+${x}=${j+x}<br>`)
document.write(`${j}+${y}=${j+y}<br>`)
document.write(`${j}+${z}=${j+z}<br>`)
document.write(`${y}+${x}=${y+x}<br>`)
document.write(`${z}+${x}=${z+x}<br>`)
}
循环语句
function test(){
for(let a = 1;a<=9;a++){
console.log(a )
}
}
测试语法
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>测试</title>
</head>
<body onload="etoak('hello','你好')">
<script>
function etoak(arg1,arg2){
alert(`${arg1}world,${arg2}世界~~`)
const SEASON = 3
if(SEASON>=1&&SEASON<=3){
console.log('春天来了')
}else if(SEASON>=4&&SEASON<=6){
console.log('夏天来了')
}else if(SEASON>=7&&SEASON<=9){
console.log('秋天来了')
}else if(SEASON>=10&&SEASON<=12){
console.log('冬天来了')
}
let i = 10
let j = 1.1
let x = 'etoak'
let y = true
let z = null
document.write(`${i}+${j}=${i+j}<br>`)
document.write(`${i}+${x}=${i+x}<br>`)
document.write(`${i}+${y}=${i+y}<br>`)
document.write(`${i}+${z}=${i+z}<br>`)
document.write(`${j}+${x}=${j+x}<br>`)
document.write(`${j}+${y}=${j+y}<br>`)
document.write(`${j}+${z}=${j+z}<br>`)
document.write(`${y}+${x}=${y+x}<br>`)
document.write(`${z}+${x}=${z+x}<br>`)
let str = ''
for(let a = 1;a<=9;a++){
for(let b = 1;b<=a;b++){
str += `${b}*${a}=${b*a}\t`
}
str += '<br />'
}
document.write(str)
}
</script>
</body>
</html>