gpt4 book ai didi

JavaScript 小费计算器

转载 作者:行者123 更新时间:2023-12-01 00:26:52 26 4
gpt4 key购买 nike

我对 Javascript 很陌生,这是我的问题我似乎无法正确理解最后两个框,并对我困惑的编码感到抱歉,因为我说过我对此还很陌生。

function FigureIt() {
DinCost = document.tip.dinCost.value;
Tip15 = (DinCost * .15)
Tip25 = (DinCost * .25)
Din15 = (DinCost * .15) + (DinCost)
Din25 = (DinCost * .25) + (DinCost)

document.tip.tip15.value = Tip15;
document.tip.tip25.value = Tip25;
document.tip.dinner15.value = Din15;
document.tip.dinner25.value = Din25;
}
<form name="tip">
How much did you pay for dinner? &nbsp; $<input type="text" name="dinCost" id="dinCost"> <br>
<input type="button" value="Calculate Tips" onclick="FigureIt()"> <br> <br> Amount of 15% tip: &nbsp; $<input type="text" name="tip15" id="tip15"> <br> Amount of 25% tip: &nbsp; $<input type="text" name="tip25" id="tip25"> <br> <br> Cost of dinner +
15% tip: &nbsp; <input type="text" name="dinner15" id="dinner15"><br> Cost of dinner + 25% tip: &nbsp; <input type="text" name="dinner25" id="dinner25"> <br>
<input type="reset" value="Erase">
</form>

最佳答案

将您输入的晚餐费用转换为数字:

DinCost = Number(document.tip.dinCost.value);

关于JavaScript 小费计算器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58902872/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com