需要找到一系列数字中最大的一个,但数字必须来自用户输入。对于这个作业,JavaScript 必须用 HTML 文档编写,这是我到目前为止所拥有的:
function getLargest(a,b,c,d,e){
let numArray = [b,c,d,e];
let largest = a;
for(let item of numArray){
if(item > largest){
largest = item;
}
}
return largest;
document.getElementById('largest').innerHTML = largest
}
let a = prompt("Enter 1st Number");
let b = prompt("Enter 2nd Number");
let c = prompt("Enter 3rd Number");
let d = prompt("Enter 4th Number");
let e = prompt("Enter 5th Number");
getLargest (a,b,c,d,e);
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h2>The Largest number is:</h2>
<p id = "largest"></p>
</body>
</html>
繁花不似锦
慕田峪7331174
相关分类