Page 1 of 1

2nd condition won't execute; gpa from number to letter grade

Posted: Sun Jan 19, 2014 7:33 pm
by Nalini

I updated my js code to ouput a letter grade instead of gpa. The logic for calculating average is working, but my second condition is not executing. They both should show letter grade. So output shows as indicated on UI Can you give me some direction?

Image

Below is my code..I have the service, dbase, UI and labels all setup correctly.

var courtesyVal = 0,
overallVal = 0,
i;

if (data.length) {

Code: Select all

 for (i = 0; i < data.length; i++) { 

     courtesyVal += data[i].grade_courtesy; 
     overallVal += data[i].grade_overall; 

 } 

 courtesyVal = (courtesyVal / data.length); 
 overallVal = (overallVal / data.length); 

}

if (courtesyVal = 4 overallVal = 4) {
courtesyVal = ("A") overallVal("A");
} else if (courtesyVal = 3 overallVal = 3) {
courtesyVal = ("B") overallVal("B");
} else if (courtesyVal = 2 overallVal = 2) {
courtesyVal = ("C") overallVal("C");
} else if (courtesyVal = 1 overallVal = 1) {
courtesyVal = ("D") overallVal("D");
} else {
courtesyVal = ("F") || overallVal("F");
}

Appery("courtesy_grade").text(courtesyVal);
Appery("overall_grade").text(overallVal);


2nd condition won't execute; gpa from number to letter grade

Posted: Sun Jan 19, 2014 9:14 pm
by maxkatz

You should try to debug the code with some static values.. instead of getting values from the UI, set some static values and see where the code fails.


2nd condition won't execute; gpa from number to letter grade

Posted: Sun Jan 19, 2014 10:10 pm
by Nalini

The code is fine when I ran with static values. I thought maybe some error with appery statement [end of script].


2nd condition won't execute; gpa from number to letter grade

Posted: Mon Jan 20, 2014 1:43 am
by maxkatz

When you use static values.. do the last two statements work?


2nd condition won't execute; gpa from number to letter grade

Posted: Mon Jan 20, 2014 3:46 pm
by Nalini

i didn't include the last two statements


2nd condition won't execute; gpa from number to letter grade

Posted: Mon Jan 20, 2014 4:16 pm
by maxkatz

You should test the entire script.


2nd condition won't execute; gpa from number to letter grade

Posted: Mon Jan 20, 2014 6:43 pm
by Maryna Brodina

Hello! What does pre overallVal("A")/pre in first condition? You have error in code, overallVal is a number, not function. Please check are there any errors in console. Also check courtesyVal and overallVal values. For example show them with alerts, maybe there is something different than you expect.