目录
1.数据的接收
var number1 =prompt("请输入第一个数字")
var number2 =prompt("请输入第二个数字")
var number3 =prompt("请输入第三个数字")
number1=parseInt(number1)
number2=parseInt(number2)
number3=parseInt(number3)
2.判断最大值 代入函数
function getMaxValue(number1,number2,number3){
//最大值
if(number1>number2){
if(number1>number3){
document.write("最大值为:"+number1)
}else{
document.write("最大值为:"+number3)
}
}else{
if(number2>number3){
document.write("最大值为:"+number2)
}else{
document.write("最大值为:"+number3)
}
}
}
3.判断最小值 代入函数
function getMinValue(number1,number2,number3){
//最小值
if(number1<number2){
if(number1<number3){
document.write("最大值为:"+number1)
}else{
document.write("最大值为:"+number3)
}
}else{
if(number2<number3){
document.write("最大值为:"+number2)
}else{
document.write("最大值为:"+number3)
}
}
}
4.输出函数
getMaxValue(number1,number2,number3)
getMinValue(number1,number2,number3)
5.总结
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>1.给三个数字,按照大小排列</title>
<script>
function getMaxValue(number1,number2,number3){
//最大值
if(number1>number2){
if(number1>number3){
document.write("最大值为:"+number1)
}else{
document.write("最大值为:"+number3)
}
}else{
if(number2>number3){
document.write("最大值为:"+number2)
}else{
document.write("最大值为:"+number3)
}
}
}
function getMinValue(number1,number2,number3){
//最小值
if(number1<number2){
if(number1<number3){
document.write("最大值为:"+number1)
}else{
document.write("最大值为:"+number3)
}
}else{
if(number2<number3){
document.write("最大值为:"+number2)
}else{
document.write("最大值为:"+number3)
}
}
}
//1.数据接收
var number1 =prompt("请输入第一个数字")
var number2 =prompt("请输入第二个数字")
var number3 =prompt("请输入第三个数字")
number1=parseInt(number1)
number2=parseInt(number2)
number3=parseInt(number3)
getMaxValue(number1,number2,number3)
getMinValue(number1,number2,number3)
</script>
</head>
<body>
</body>
</html>