2014-11-29 14 views
-5

자바 스크립트는 다음과 같은 지침을 따라야합니다 : 소득이 $ 70,000 세율이 70 %에서 (% 기호를 시작 이상하지 않습니다 경우초보자

  1. 을 쇼)
  2. 소득이
  3. 그렇지 않으면 세율이 25 %에서 시작 $ 20,000 세율은 10 %에서 시작 이하 (% 기호가 표시되지 않습니다) 인 경우

나는 내 기능이 작동하지 않습니다

도움이 될 것이다이 질문을 통해 얻을 수 있도록 할 것 천 실수 아무것도하지만 거기에 알고 난조차 궤도에 확신 메신저입니다

<html> 
<head> 
<script language = "JavaScript"> 

function() 
{ 
var IncomeInput, 
TaxRateCalc; 

IncomeInput = parseInt(document.TaxInfo.Income.value); 

if (IncomeInput>=70000) 
{ 
    TaxRateCalc = "70"; 
} 
else if (IncomeInput=<20000) 
{ 
    TaxRateCalc = "10"; 
} 
else() 
{ 
    TaxRateCalc = "25"; 
} 
document.TaxInfo.TaxRate.value = TaxRateCalc; 
} 
</script> 
</head> 
<body> 
<center> 
The Taxman 
</center> 

<form name = "TaxInfo"> 
<table border = "3"> 
Your Tax Information<br> 
<tr><td>Income</td> <td> <input name = "Income" value = "10000000" size = "20"> </td> </tr> 
<tr><td>RRSP</td> <td> <input name = "RRSP" value ="0" size = "20"></td> </tr> 
<tr><td>Tax Rate</td> <td> <input name = "TaxRate" value = "" size = "20"> </td> </tr> 
<tr><td>Taxes Paid</td> <td> <input name = "TaxesPaid" value = "0" size = "20"> </td> </tr> 
<tr><td>Refund or Due</td> <td> <input name = "RefundOrDue" value = "0"size = "20"> </td> </tr> 
</table> 
</form> 

<form name = "Extra Deductions"> 
Extra Deductions- 
Children <input name = "Children" type = "radio"> 
Spouse <input name = "Spouse" type = "radio"> 
Both <input name = "Both" type = "radio"> 
None <input name = "None" checked type = "radio"> 
</form> 

<form name = OldPeople > 
Over age 65? <input name = "Over age 65?" type = "checkbox" > 
</form> 

<form name = "Selection"> 
Special Cases 
<select name="SpecialCases"> 

    <option value ="None"> None </option> 
    <option value ="Hardship Claimed"> Hardship Claimed </option> 
    <option value ="Mercy"> Mercy </option> 
    <option value ="Lawyer"> Lawyer </option> 
</select> 
</form> 

<form name = "buttons"> 
<input type = "button" value = "Calculate your tax" onclick = ""> 
<input type = "button" value = "Clear Display Area" onclick= "aloop"> 
</form> 

<form name = "YourTaxRate"> 
Your Tax Rate<br> <textarea name = "TaxRate" rows = "15" cols = "25"> </textarea> 
</form> 
</body> 
</html> 
+0

숙제를, 맞죠? – JuanSedano

+0

** ** ** 모든 기사 ** [여기] (http://www.w3schools.com/js/default.asp)를 먼저 읽으시 길 바랍니다. 단지 몇 시간 밖에 걸리지 않습니다. – skobaljic

+0

예. 불행히도 –

답변

0

그 중 얼마나 많은 것이 템플릿인지 궁금합니다. 오 그런데, 너 자신에 대한 믿음을 가져라. 나는 당신이 썼던 것이 얼마나 많은지 모르지만 기능 자체는 IncomeInput<=20000 비교기 만 전환해야했습니다.

<html> 
<head> 
</head> 


<body> 

<script> 

function calcTax() { 

    var IncomeInput, TaxRateCalc; 

    IncomeInput = parseInt(document.TaxInfo.Income.value); 

    if (IncomeInput>=70000) 
    { 
     TaxRateCalc = "70"; 
    } 
    else if (IncomeInput<=20000) 
    { 
     TaxRateCalc = "10"; 
    } 
    else 
    { 
     TaxRateCalc = "25"; 
    } 
    document.YourTaxRate.TaxRate.value = TaxRateCalc; 

} 

</script> 

<center> 
The Taxman 
</center> 


<form name = "TaxInfo"> 
    <table border = "3"> 
     Your Tax Information<br> 
     <tr><td>Income</td> <td> <input name = "Income" value = "10000000" size = "20"> </td> </tr> 
     <tr><td>RRSP</td> <td> <input name = "RRSP" value ="0" size = "20"></td> </tr> 
     <tr><td>Tax Rate</td> <td> <input name = "TaxRate" value = "" size = "20"> </td> </tr> 
     <tr><td>Taxes Paid</td> <td> <input name = "TaxesPaid" value = "0" size = "20"> </td> </tr> 
     <tr><td>Refund or Due</td> <td> <input name = "RefundOrDue" value = "0"size = "20"> </td> </tr> 
    </table> 
</form> 

<form name = "Extra Deductions"> 
    Extra Deductions- 
    Children <input name = "Children" type = "radio"> 
    Spouse <input name = "Spouse" type = "radio"> 
    Both <input name = "Both" type = "radio"> 
    None <input name = "None" checked type = "radio"> 
</form> 

<form name = "OldPeople" > 
    Over age 65? <input name = "Over age 65?" type = "checkbox" > 
</form> 

<form name = "Selection"> 
    Special Cases 
    <select name="SpecialCases"> 

     <option value ="None"> None </option> 
     <option value ="Hardship Claimed"> Hardship Claimed </option> 
     <option value ="Mercy"> Mercy </option> 
     <option value ="Lawyer"> Lawyer </option> 
    </select> 
</form> 

<form name = "buttons"> 
    <input type = "button" value = "Calculate your tax!" onclick = "calcTax()" /> 
    <input type = "button" value = "Clear Display Area" onclick = "" /> 
</form> 

<form name = "YourTaxRate"> 
    Your Tax Rate<br> <textarea name = "TaxRate" rows = "15" cols = "25"> </textarea> 
</form> 

</body> 
</html> 
+0

도움을 주셔서 감사하고 그것을 믿거 나 말거나 모든 기능을 잘 이해하고있는 것 같지 않습니다. –

+0

무엇? 기수는 선택적인 매개 변수입니다. 왜이 예제에서 기수 10을 변경하고 싶습니까? – luuksen

+0

아니요, 항상 사용하십시오 (BTW, 위의 제 제안을 삭제하는 것이 아닙니다 ...). –

0

이 시도 :

function myFunction() { 
 
    var income = document.getElementById("income").value; 
 
    var taxRateCalc; 
 
    if (income == "") { 
 
    alert("Please type a valid income."); 
 
    } else { 
 
    if (income >= 70000) { 
 
     taxRateCalc = "70"; 
 
    } 
 
    else if (income <= 20000) { 
 
     taxRateCalc = "10"; 
 
    } 
 
    else { 
 
     taxRateCalc = "25"; 
 
    } 
 
    document.getElementById("taxRate").value = taxRateCalc; 
 
    } 
 
}
Income: <input type="text" id="income"> 
 
<button onclick="myFunction()">Validate Income</button><br><br> 
 
Tax Rate: <input type="text" id="taxRate" readonly>

+0

덕분에 도움을 주셔서 감사합니다! –

+1

감사합니다. Roko, 훨씬 나아졌습니다! – JuanSedano