Javascript 需要帮助制作小费计算器吗

Javascript 需要帮助制作小费计算器吗,javascript,html,Javascript,Html,我需要做一个程序,将一个数字乘以.15,这样你就知道你需要留下多少小费 我试图将账单输入放入函数中的一个新变量中,因为当我从新变量中取出number()时,我会得到小费总额,但这样做不会导致任何结果,因为JavaScript不知道这是一个数 <body> <input id="bill" placeholder ="How much was you meal?" /> <button onclick ="tip()"> submit&l

我需要做一个程序,将一个数字乘以.15,这样你就知道你需要留下多少小费

我试图将账单输入放入函数中的一个新变量中,因为当我从新变量中取出
number()
时,我会得到小费总额,但这样做不会导致任何结果,因为JavaScript不知道这是一个数

   <body>
    <input id="bill" placeholder ="How much was you meal?" />

    <button onclick ="tip()"> submit</button>

    <script> let bill = document.querySelector("#bill")

        function tip(){

            let yourTip = number( bill.value * .15)
            let total = yourTip * bill

            console.log ("Your tip  is $" + yourTip)
            console.log ("Your total after the tip is $" + total)
        }
    </script>
   </body>

提交
let bill=document.querySelector(“#bill”)
函数提示(){
让你的小费=数字(bill.value*.15)
让总数=你的小费*账单
console.log(“您的小费是$”+您的小费)
console.log(“提示后的总数为$”+总数)
}
我不需要只在控制台的屏幕上打印,提示%也不需要更改。

试试这个:


身体{
文本对齐:居中;
}
算计
小费:0美元
总额:0美元
let bill=document.querySelector(“#bill”)
函数提示(){
让bill=document.getElementById('bill').value;
设billNum=parseInt(比尔);
让你的小费=billNum*.15;
让总数=你的小费+比尔纳姆;
document.getElementById('tip').innerHTML=“tip:$”+yourTip;
document.getElementById('total').innerHTML=“总计:$”+总计;
}
试试这个

 <input id="bill" type="number" placeholder="How much was you meal?" />

<button onclick="tip()">submit</button>

<script>
  function tip() {
    var bill = parseInt(document.getElementById("bill").value);
    console.log(bill);

    let yourTip = bill * 0.15;
    let total = yourTip + bill;

    console.log("Your tip  is $" + yourTip);
    console.log("Your total after the tip is $" + total);
  }
</script>

提交
函数提示(){
var bill=parseInt(document.getElementById(“bill”).value);
控制台日志(账单);
让你的小费=账单*0.15;
总数=小费+账单;
log(“您的小费是$”+您的小费);
log(“提示后的总数为$”+总数);
}

也许parseInt会帮助您?此外,您的账单声明是全局非阻塞的,因此在进行任何计算之前,您应该为账单设置var not letparseInt。为什么会有什么区别?