0
Please help me alter my Javascript. I NEED A "FOR LOOP".
here is a link to my code - "Blaines Grade Sheet" https://code.sololearn.com/Wk2zB9PseLVP/# My code does exactly what I want it to, however I am hoping someone can alter my code to incorporate an array and a for loop, so I can see what that looks like. I know there is probably a more elegant solution to my code. I want my code to have same outcome that it already has, so that it loops through every students GPA and adds them together to get a total class GPA, I just NEED a for loop added somehow.
10 Answers
+ 2
Blaine P
https://code.sololearn.com/WM2Je4dpQI9M/?ref=app
Code works the same way as before, just now it's shorter and more efficient. I'm sure I could have made it even more efficient, but in the end it's your work to code to your likeness.
Enjoy!
+ 1
If no one has altered it for you in 2 hours, I'll do so just to show you how arrays are used.
+ 1
Working on it now.
+ 1
Working on it now.
+ 1
Wow that is crazy how much more simple that looks.
i was really confused for a sec as to why in the for loop you were using a "1" instead of an "i", but there "i's" look like "1's" :P
this is great man!
+ 1
Hey quick question. Why does the GPA change everytime we click the button even if the students grades stay the same?
+ 1
That is because in the code, results just adds the gpas to the current result. So if results was 2.0 as avg GPA, it'll add the 5 scores again to 2.0 and then find the average. A quick fix would be to put the result = 0 inside the function like:
function AddGrade(){
var result = 0;
This way it will always reset before recalculating. I've already changed it in the code and saved the change, go check it again and see for yourself.
+ 1
Okay sweet man. I also added result.toFixed(1); at the end of function to shorten the GPA decimals.
Thank you again, man! This helps me out alot. :)
0
Okay thank you so much!
0
Right on, I cant thank you enough.