Djcottrell
New Member
- Messages
- 29
- Reaction score
- 0
- Points
- 0
I am a php programmer and I am just starting to learn the Javascript functions. For some reason I can not figure this one out.
A little about this code. The saves array is generated by a php include. Long story short the value of save1-5 is a decimal number such as 1.0, 1.5, 2.0, 2.5. This is being used for a review system. I am trying to collect the values of save1-5 and averaging them out.
Lets say x=0.5 and y=1.5. If i add x+y I dont get 2 i get 0.52.5
Is there an easier method in which to create this in JS.
A little about this code. The saves array is generated by a php include. Long story short the value of save1-5 is a decimal number such as 1.0, 1.5, 2.0, 2.5. This is being used for a review system. I am trying to collect the values of save1-5 and averaging them out.
Lets say x=0.5 and y=1.5. If i add x+y I dont get 2 i get 0.52.5
Is there an easier method in which to create this in JS.
Code:
[COLOR=#000000][FONT=monospace]var saves = new Array('save1','save2','save3','save4','save5');[/FONT][/COLOR]
for(var i in saves){
var y = eval(saves[i])*1;
x=x+y;
}
var arraySize = saves.length;
var average = x/arraySize;
var result = average.toFixed(1);
Last edited: