/    Sign up×
Community /Pin to ProfileBookmark

begginer – problem with function

Hello everybody!
I am really beginner ? and had problem with function
it doesn’t work (when I click button) and question is where is my mistake?
Thanks!
this is a part of script:
<script>
var L=0;
var M=0;
var H=0;
function Count() {
var costAvg = document.getElementById(“avgCost”).value;

if (average<1000 && average>=100){
++M;
}
if (average<100){
++L;
}
if (average>1000) {
++H;
}
document.getElementById(“avgL”).value=L;
document.getElementById(“avgM”).value=M;
document.getElementById(“avgH”).value=H;
} // end function Count
</script>

<tr>
<td colSpan=2>
<P align=center><INPUT id=calcCts onclick=Count() type=button value=”Display Average Count”>
</td>
</tr>

<tr>
<td>Avr Cost <$100</td>
<td><input id=avgL></td>
</tr>

<tr>
<td>Avr Cost >=$100 -<1000</td>
<td><input id=avgM></td>
</tr>

<tr>
<td>Avr Cost – >$1000</td>
<td><input id=avgH></td>
</tr>

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@skywalker2208Nov 22.2008 — where is the average variable suppose to be coming from that you are using in your if statements?
Copy linkTweet thisAlerts:
@white_catauthorNov 22.2008 — thanks for reply. this is code at the beginning

<script type="text/javascript">

function average_cost(){ // calculates average cost of item

var Cost1 = parseFloat(document.getElementById("cost1").value);

var Cost2 = parseFloat(document.getElementById("cost2").value);

var Cost3 = parseFloat(document.getElementById("cost3").value);

var Cost4 = parseFloat(document.getElementById("cost4").value);

var average = (Cost1 + Cost2 + Cost3 + Cost4) / 4;

document.getElementById("avgCost").value=average;

}

var L=0;

var M=0;

var H=0;

function Count() {

var costAvg = document.getElementById("avgCost").value;

if (average<1000 && average>=100){

++M;

}

if (average<100){

++L;

}

if (average>1000) {

++H;

}

document.getElementById("avgL").value=L;

document.getElementById("avgM").value=M;

document.getElementById("avgH").value=H;

} // end function Count

</script>

<center>

<form name = myForm>

<table border=1>

<tr>

<td>Item number</td>

<td><input id=itemNumber on change=item_number()></td>

</tr>

<tr>

<td>Cost 1</td>

<td><input id=cost1></td>

</tr>

<tr>

<td>Cost 2</td>

<td><input id=cost2></td>

</tr>

<tr>

<td>Cost 3</td>

<td><input id=cost3></td>

</tr>

<tr>

<td>Cost 4</td>

<td><input id=cost4></td>

</tr>

<tr>

<td colSpan=2>

<P align=center><INPUT id=calcAvg onclick=average_cost() type=button value="Calculate Average Cost">

</td>

</tr>

<tr>

<td>Average</td>

<td><input type=avgCost></td>

</tr>

<tr>

<td colSpan=2>

<P align=center><INPUT id=calcCts onclick=Count() type=button value="Display Average Count">

</td>

</tr>

<tr>

<td>Avr Cost <$100</td>

<td><input id=avgL></td>

</tr>

<tr>

<td>Avr Cost >=$100 -<1000</td>

<td><input id=avgM></td>

</tr>

<tr>

<td>Avr Cost - >$1000</td>

<td><input id=avgH></td>

</tr>

</body>

</html>
×

Success!

Help @white_cat spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...