项目一:定义最大值函数,假设a,b,c进行比较,得出假设后的最大值
function getMaxValue(a, b, c) {
if (a > b) {
//a目前最大
if (a > c) {
//a最大
console.log(a)
} else {
// c 最大
console.log(c)
}
} else {
// b 目前最大
if (b > c) {
//b最大
console.log(b)
} else {
//c 最大
console.log(c)
}
}
}
项目二:定义最小值函数,假设a,b,c进行比较,得出假设后的最小值
function getMinValue(a, b, c) {
if (a < b) {
//a目前最小
if (a < c) {
//a最小
return a
} else {
// c 最小
return c
}
} else {
// b 目前最小
if (b < c) {
//b最小
return b
} else {
//c 最小
return c
}
}
}
项目三:设置三个数字的输入框
var number1 = prompt("请输入第一个数字:")
var number2 = prompt("请输入第二个数字:")
var number3 = prompt("请输入第三个数字:")
项目四:函数调用
//函数的调用
// getMaxValue(10,20,30)
console.log(getMaxValue(number1,number2,number3))
console.log(getMinValue(number1,number2,number3))
全部代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script>
//作业1:使用函数完成给定三个数字,找出最大值和最小值
//a b c
//定义函数
function getMaxValue(a, b, c) {
if (a > b) {
//a目前最大
if (a > c) {
//a最大
console.log(a)
} else {
// c 最大
console.log(c)
}
} else {
// b 目前最大
if (b > c) {
//b最大
console.log(b)
} else {
//c 最大
console.log(c)
}
}
}
// 定义函数
function getMinValue(a, b, c) {
if (a < b) {
//a目前最小
if (a < c) {
//a最小
return a
} else {
// c 最小
return c
}
} else {
// b 目前最小
if (b < c) {
//b最小
return b
} else {
//c 最小
return c
}
}
}
var number1 = prompt("请输入第一个数字:")
var number2 = prompt("请输入第二个数字:")
var number3 = prompt("请输入第三个数字:")
//函数的调用
// getMaxValue(10,20,30)
console.log(getMaxValue(number1,number2,number3))
console.log(getMinValue(number1,number2,number3))
</script>
</head>
<body>
</body>
</html>