我有一個JS代碼來計算一個數字的倍數。我想在我的HTML文件中加入相同的內容。所以當我點擊「提交」按鈕時,它給了我答案。以下是我的代碼:Javascript代碼將被嵌入在HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta author="Shruti Paliwal">
<title>Project Euler Solutions</title>
<script language="javascript" type="text/javascript">
function multiples()
{
var i;
sum=0;
for(i=1;i<1000;i++)
{
if(i%3 === 0 || i%5 === 0)
{
sum+=i;
}
}
}
document.getElementById('sum').value = sum;
</script>
</head>
<body>
<h3>
<div id="header">
Project Euler
<sub>.net</sub>
</h3>
</div>
<br />
<br />
<p class="problem1" id="problem">
<b>
Multiples of 3 and 5
</b>
<div class="boundary" id="boundary">
<div class="content">
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
<br />
Find the sum of all the multiples of 3 or 5 below 1000.
<br />
<br />
<form>
<input type="text" name="value">
<input type="button" onclick="sum()" value="Submit" />
</form>
</div>
</p>
</div>
</style>
</body>
</html>
需要幫助才能在我的網頁上顯示此代碼的輸出。計算倍數的邏輯在JS控制檯上工作正常。但是,沒有得到如何納入2!
沒有代碼 – brk
您似乎沒有在這方面付出太多的努力。 ; P – Matt
第37行是罪魁禍首 –