シンプルで頼れる掛け算計算機
以下は、HTMLとJavaScriptで作られた掛け算計算機のコードです。
下のコードをコピペして、kakezan.htmlという名前で保存してください。ブラウザで開くとすぐに使えます!
掛け算計算機
<script>
function calc() {
const n1 = parseFloat(document.getElementById(“num1”).value);
const n2 = parseFloat(document.getElementById(“num2”).value);
const resultArea = document.getElementById(“answer”);
if (isNaN(n1) || isNaN(n2)) {
resultArea.innerText = “両方の数字を入力してください。”;
resultArea.style.color = “#e74c3c”;
} else {
resultArea.innerText = `答え:${n1 * n2}`;
resultArea.style.color = “#2c3e50”;
}
}
</script>

コメント