逻辑控制语句

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>`)
}
//运行结果
/**
		10+1.1=11.1
		10+etoak=10etoak
		10+true=11
		10+null=10
		1.1+etoak=1.1etoak
		1.1+true=2.1
		1.1+null=1.1
		true+etoak=trueetoak
		null+etoak=nulletoak
*/

循环语句

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>`)

			  //在页面上使用document.write()来输出九九乘法表
				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>
01-23 06:46