Javascript帮助 - 信用小时计算器 [英] Javascript help - Credit hour calculator

查看:60
本文介绍了Javascript帮助 - 信用小时计算器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。我是Javascript的新手,我想制作一个学分计算器。我几乎完成了,但是我希望它能够计算学分总数:例如,如果我输入3个学分,总共9个学分。我知道这可能听起来令人困惑,但现在所做的只是总数。现在有三个文本字段,称为1学分,2学分和3学分。例如,如果有人投入他们正在参加1学分课程,2学分2小时课程和3学分3小时课程,我希望总数达到14学分。这是我的JS Fiddle文件,所以你可以更好地理解它: JS Fiddle



另外这是我到目前为止的代码:



Hello. I am new to Javascript and I want to make a credit hour calculator. I have it almost complete, but I want it to calculate the total number of credit hours: for example if I put in three 3 credit hours that is 9 credit hours total. I know this might sound confusing but right now all it does is add up the total number. Right now there are three text fields called 1 credit hour, 2 credit hours, and 3 credit hours. For example if someone were to put in that they were taking 1 1credit hour course, 2 2credit hour course and 3 3credit hour courses I want the total to come out to be 14 credit hours. Here is my JS Fiddle file for it so you can make more sense of it: JS Fiddle

Also Here is my code I have so far:

function doCalc() 
{
var value1 = document.getElementById("credit1").value;
var value2 = document.getElementById("credit2").value;
var value3 = document.getElementById("credit3").value;
var total = Number(value1) + Number(value2) + Number(value3);
document.getElementById("output").value = total;
}







1 credit hour: <input type="number" id="credit1">
<br /> 

2 credit hour: <input type="number" id="credit2">
<br /> 

3 credit hour: <input type="number" id="credit3">
<br /> 

Total: <input id="output">
<br />

<button >Calculate</button>

推荐答案

检查一下:JavaScript算术 [ ^ ]


这篇关于Javascript帮助 - 信用小时计算器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆