<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
// 1. 求任意数组中的最大值并返回这个最大值
// 2. 求任意数组中的最小值并返回这个最小值
// 3. 求任意2个数中的最大值, 并返回
function getArrayMax(array = []){
let max = array[0]
for(let i = 0; i < array.length; i++){
if(max < array[i]){
max = array[i]
}
}
return max
}
function getArrayMin(array = []) {
let min = array[0]
for (let i = 0; i < array.length; i++) {
if (min > array[i]) {
min = array[i]
}
}
return min
}
function getMax(a = 1,b = 0){
if(a < b){
a = b
}
return (`最大值是 ${a}`)
}
document.write(getArrayMax([29, 349, 34]),'<br>')
// document.write(getArrayMin([29, 349, 34]), '<br>')
// document.write(getMax(23, 23434))
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
// 需求: 用户输入秒数,可以自动转换为时分秒
// 分析:
// ①:用户输入总秒数
// ②:计算时分秒(封装函数) 里面包含数字补0
// ③:打印输出
// 计算公式:计算时分秒
// 小时: h = parseInt(总秒数 / 60 / 60 % 24)
// 分钟: m = parseInt(总秒数 / 60 % 60)
// 秒数: s = parseInt(总秒数 % 60)
function getFormatTime(seconds = 0){ // 一天共 86400s
if(0 <= seconds <= 86400){
let h = parseInt(seconds / 60 / 60 % 24) // 时
let m = parseInt(seconds / 60 % 60) // 分
let s = parseInt(seconds % 60) // 秒
//小于10 则补0
h = h < 10 ? ('0' + h) : h
m = m < 10 ? ('0' + m) : m
s = s < 10 ? ('0' + s) : s
return `${h}:${m}:${s}`
}else{
return `input error`
}
}
document.write(getFormatTime(10000))
</script>
</body>
</html>