借金の返済計画アプリ
借金の金額を入力してください:
月々の返済額を入力してください:
以下が借金の返済計画アプリの実装例です。
```
<!DOCTYPE html>
<html>
<head>
<title>借金の返済計画アプリ</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<h1>借金の返済計画アプリ</h1>
<p>借金の金額を入力してください:</p>
<input type="number" id="debt-amount">
<p>月々の返済額を入力してください:</p>
<input type="number" id="monthly-payment">
<button onclick="calculate()">計算する</button>
<div id="result"></div>
<script>
function calculate() {
const debtAmount = parseInt(document.getElementById('debt-amount').value);
const monthlyPayment = parseInt(document.getElementById('monthly-payment').value);
if (isNaN(debtAmount) || isNaN(monthlyPayment)) {
return;
}
let remainingDebt = debtAmount;
let totalMonths = 0;
while (remainingDebt > 0) {
remainingDebt = remainingDebt - monthlyPayment;
totalMonths++;
}
const resultElement = document.getElementById('result');
resultElement.innerHTML = '月々の返済額が ' + monthlyPayment + ' 円だと、' + totalMonths + ' か月後に借金が完済します。';
if (totalMonths > 12) {
resultElement.innerHTML += '<br><br>まあ、' + totalMonths + ' か月も待てば返済完了ですから、余裕があると思って日々を過ごしましょう。';
}
}
</script>
</body>
</html>
```
このアプリは、ユーザーに借金の金額と月々の返済額を入力してもらい、返済完了までの月数を計算して表示します。余裕がある場合には面白いジョークをつけています。また、入力値が数値でない場合は計算をしないようにして、セキュリティ脆弱性を回避しています。