console
var globalVariable1 = 0;
function test1() {
document.write(localVariable1+ "<br/>");
var localVariable1 = 2;
document.write(globalVariable1 + "<br/>");
document.write(localVariable1+ "<br/>");
}
document.write(globalVariable2 + "<br/>");
test1();
var globalVariable2 = 1;
function test2() {
var localVariable2 = 3;
}
test2();
document.write(globalVariable1 + "<br/>");
document.write("---------------------------------<br/>")
function addSum(a, b)
{
var sum = a + b;
return sum;
}
var n = addSum(1, 2) + 100;
document.write(n+ "<br/>");
document.write("---------------------------------<br/>")
function isLeapYear(year)
{
if ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0))
{
return year + "year is an leap year";
}
else
{
return year + " is not a leap year";
}
}
document.write(isLeapYear(2022));
document.write("---------------------------------<br/>")
function writeDocument(variable) {
document.write(variable + "<br/>");
}
function getMax(a,b,c,d) {
var maxNum;
maxNum = (a > b) ? a : b;
maxNum = (maxNum > c) ? maxNum : c;
maxNum = (maxNum > d) ? maxNum : d;
return maxNum;
}
document.write("5个数中的最大值为:" + getMax(7,16,50,-9));
//函数在超链接中的调用
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script>
function expressMes()
{
alert("很烦");
}
</script>
</head>
<body>
<a href="javascript:expressMes()">wadada</a>
</body>
</html>