The Bill Is 20015 چالش 3 از جلسهی 37، متوسط
این برنامهی جاوااسکریپت قیمت را با تخفیف و با هزینهی ارسال حساب میکند. خط اول درست درمیآید (180)، ولی خط دوم میشود 20015!
۱. به ورودیهای discount و withDelivery نوع number بده و نوع خروجی هر دو را بنویس.
۲. خطهای قرمز تازه باگ را نشان میدهند. مقدار را درست کن، نه نوع را.
برنامه باید 180 و بعد 215 را نشان بدهد.
<style>
body { font-family: sans-serif; text-align: center; padding: 16px; }
button, input, select { font-size: 16px; min-height: 40px; margin: 4px; }
#out { direction: ltr; text-align: left; font: 16px monospace; margin: 12px 0; padding: 12px; min-height: 28px; border-radius: 12px; background: #0f172a; color: #e2e8f0; white-space: pre-wrap; overflow-wrap: anywhere; }
#out .line { min-height: 22px; }
</style>
<pre id="out"></pre>
<script type="text/typescript">
function discount(price, percent) {
return price - price * percent / 100;
}
function withDelivery(price, delivery) {
return price + delivery;
}
let price = "200";
show(discount(price, 10));
show(withDelivery(price, 15));
</script>
راهنما و جواب این چالش · برگشت به درس جلسهی 37: اسبابکشی، قدم اول · چالش بعدی: The Missing Grade
بیشتر بخوان: جاوااسکریپت چیست؟ از دکمهی وب تا Node.js