2016-10-12 278 views
0

我試圖顯示總工作時間讓說40然後 允許輸入小時工資讓說35 ..最後 顯示1400這是總數..可以有人請舉手。Javascript顯示輸出計算

<!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> 
+0

'ParseInt();'或'ParseFloat()'應該有參數。 – ASDFGerte

+0

這個'hours = ParseInt();'應該做什麼? – j08691

回答

0

看起來不像你在hourspayRate存儲任何東西。改爲嘗試hours = ParseInt(input);payRate = ParseFloat(input);

+0

謝謝你.. :) –

0

你必須把該變量的parseInt函數和ParseFloat裏面,JS是區分大小寫的,解決您的外殼:

hours = parseInt(input); 

此外,獲得每一個變量之前,使用「無功」的習慣第一你使用它的時間......或者把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>");