JavaScript计算帮助(乘以时间)(JavaScript Calculation Help (Multiplying Time))

编程入门 行业动态 更新时间:2024-10-26 20:27:40
JavaScript计算帮助(乘以时间)(JavaScript Calculation Help (Multiplying Time))

我有一些代码,我用来从两个输入生成计算,但我无法生成我需要的结果。

我有两个输入(让我们称之为input1和输入2)。 输入值时,它会根据以下内容计算:

(input1 x 0.156 $)x((输入2 x 15秒)x 4.2)x 12个月

我原来的代码如下:

var calculation = function() { var input1 = document.getElementById('people').value; var input2 = document.getElementById('stories').value; var result = Math.floor(input1 * 0.2 * input2 * 30); document.getElementById('result').innerHTML = result; return false; }

这是变化的结果,我很难改变(上面的代码用于不同的计算)。 任何帮助将不胜感激!

I have some code that I was using to generate a calculation from two inputs but am having trouble generating the result I need.

I have two inputs (let's call them input1 and input 2). When you enter in a value, it calculates it based on the following:

(input1 x 0.156$) x ( (input2 x 15 seconds) x 4.2) x 12 months

My original code is as follows:

var calculation = function() { var input1 = document.getElementById('people').value; var input2 = document.getElementById('stories').value; var result = Math.floor(input1 * 0.2 * input2 * 30); document.getElementById('result').innerHTML = result; return false; }

It's the var result that I'm having difficulty changing (the code above was for a different calculation). Any help would be greatly appreciated!

最满意答案

在我看来,您没有正确实施您的公式,请尝试将其更改为:

var result = Math.floor((input1 * 0.156) * ((input2 * 15)*4.2)*12);

告诉我们4.2代表什么也是很好的。

这是一个有效的JSFiddle

It looks to me that you are not implementing your formula correctly, try changing it to:

var result = Math.floor((input1 * 0.156) * ((input2 * 15)*4.2)*12);

It also will be good to tell us what 4.2 stands for.

Here's a working JSFiddle

更多推荐

本文发布于:2023-07-07 09:08:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1061425.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:时间   JavaScript   Calculation   Time   Multiplying

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!