JavaScriptでプログラミングをしていると、処理の管理や、同じ処理を繰り返し使いたい時があるかと思います。
そのような時はfunction(関数)が便利です。
今回は、function(関数)を使って、税込み金額を表示してみました。
税込み価格表示
1 | < p id = "includetax" ></ p > |
1 2 3 4 5 | var total = function (price) { var tax = 0.1; return price + price * tax; } document.getElementById( 'includetax' ).textContent = '価格は' + total(3000) + '円(税込み)です。' |
価格は3300円(税込み)です。
コメント