Nalini
Posts: 0
Joined: Tue Jan 14, 2014 2:49 pm

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

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);

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

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

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.

Nalini
Posts: 0
Joined: Tue Jan 14, 2014 2:49 pm

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

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

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

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

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

Nalini
Posts: 0
Joined: Tue Jan 14, 2014 2:49 pm

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

i didn't include the last two statements

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

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

You should test the entire script.

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

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

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.

Return to “Issues”