# 利用 數字變數,製作情境計算題 (範例練習) - HTML: ``` <body> <h1>財財買紅豆餅</h1> <p>我來到一個超市,一個紅豆餅:<em id="cookiePrice"></em>元。</p> <p>我的口袋僅有:<em id="myMoney"></em>元。</p> <p>所以我差了:<em id="gapMoney"></em>元。</p> <p>如果購買5個紅豆餅,總共需要:<em id="needMoney"></em>元。</p> </body> ``` - JS: ``` var cookiePrice = 40; document.getElementById('cookiePrice').textContent = cookiePrice; var myMoney = 25; document.getElementById('myMoney').textContent = myMoney; var gapMoney = myMoney - cookiePrice; document.getElementById('gapMoney').textContent = gapMoney; var needMoney = cookiePrice * 5; document.getElementById('needMoney').textContent = needMoney; ``` ###### tags: `JavaScript - 學徒篇`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up