Why doesn’t my code run on the browser?
<!DOCTYPE html>
<html>
<head>
<title>algorithm</title>
</head>
<body>
<p align="center">Input : <input type="text" name="Input" id="data"></p><br>
<div align="center"><button id="save">Save</button></div><br>
<div align="center"><button id="end">End</button></div>
<script>
let maxList = [];
let minList = [];
var input;
var our_Data = [];
function input(){
while (true){
if(document.getElementById('save').clicked == true){
input = getElementById('data').value;
our_Data.push(input);
}
else if(document.getElementById('end').clicked == true){
break;
}
}
}
function search(theList = []) {
console.log('theList', theList)
if (theList.length <= 2) {
console.log(theList)
maxList.push(Math.max(...theList))
minList.push(Math.min(...theList))
}
else if (theList.length > 2) {
let _cloneList = Array.from(theList);
let newList = _cloneList.splice(0, 2);
console.log('theList', theList, 'newList', newList);
maxList.push(Math.max(...newList))
minList.push(Math.min(...newList))
return search(theList.splice(2))
}
}
input()
search(our_Data)
console.log(`max = `, Math.max(...maxList))
document.write(`max = ${Math.max(...maxList)}<br>`)
console.log(`min = `, Math.min(...minList))
document.write(`min = ${Math.min(...minList)}`)
</script>
</body>
</html>