Javascript显示输出计算

时间:2016-10-12 16:24:32

标签: javascript css html5

我试图显示工作总时数,然后说40     允许输入小时工资让我们说35 ..最后     显示1400这是总数。可以请某人伸手。

<!DOCTYPE html> <html> <head> <meta charset="utf-8">     <title>
    assignment3</title> <script type= "text/javascript"> <!--    var name;
    //string enterted by user
               var input;   //string enterted by user
               var hours;  //string enterted by user
               var payRate; //string enterted by user
               var grossPay; //string enterted by user

               // read the name

               name = window.prompt("What is your name?");   /*paranthesis missing and quotation marks misplaced */
               input = window.prompt("Enter the hours you worked."); 
               hours = ParseInt();

               input = window.prompt("Enter you hourly wage."); 
               payRate = ParseFloat();  

               grossPay = hours * payRate;

               //result
               document.writeln ("<h1> Hello" + name + " your gross pay is $" + grossPay+" <h1>");         
                    //-->        </script>   </head>     <body> </body>     </html>

2 个答案:

答案 0 :(得分:0)

您似乎不会在hourspayRate中存储任何内容。请改为hours = ParseInt(input);payRate = ParseFloat(input);

答案 1 :(得分:0)

你必须将变量放在ParseInt和ParseFloat中,并且JS区分大小写,修复你的外壳:

hours = parseInt(input);

此外,养成使用&#34; var&#34;的习惯。在第一次使用它之前在每个变量之前...或者将var放在顶部以养成最佳实践的习惯(不创建全局变量)。

var input;

var name = window.prompt("What is your name?");   /*paranthesis missing and var quotation marks misplaced */
input = window.prompt("Enter the hours you worked."); 
var hours = parseInt(input);

input = window.prompt("Enter you hourly wage."); 
var payRate = parseFloat(input);  

var grossPay = hours * payRate;

//result
document.writeln ("<h1> Hello" + name + " your gross pay is $" + grossPay+" <h1>");