1 Replies - 2013 Views - Last Post: 02 November 2012 - 02:15 AM

#1 mikecrisis69  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 16-October 12

Grade Calculator JavaScript

Posted 16 October 2012 - 02:21 PM

I need help figuring out how to get a letter grade from this. The code is work that I did on another application now Im changing it to the grade calculator. It was a loan calculator application. It was too hard to start from scratch. Thanks in advanced.

 function calculateAndDisplayValue(e)
{	
	Ti.API.info('Button id = ' + e.source.id);
			
		if (tfPOne.value == '0' || tfPOne.value >= 100) {
		var errorDialog1 = Titanium.UI.createAlertDialog({
			title: 'Hol Up!',
			message: 'You must enter a Grade for Project 1.'			
		});
		errorDialog1.show();}
		if (tfPTwo.value == '0' || tfPTwo.value >= 100) {
		var errorDialog2 = Titanium.UI.createAlertDialog({
			title: 'Hol Up!',
			message: 'You must enter a Grade for Project 2.'
		});
		errorDialog2.show();}
		if (tfPThree.value == '0' || tfPThree.value >= 100) {
		var errorDialog3 = Titanium.UI.createAlertDialog({
			title: 'Hol Up!',
			message: 'You must enter a Grade for Project 3.'
		});
		errorDialog3.show();}
		if (tfPart.value == '0' || tfPart.value >= 100) {
		var errorDialog4 = Titanium.UI.createAlertDialog({
			title: 'Hol Up!',
			message: 'You must enter a Participation Grade.'
		});
		
		errorDialog4.show();}
		if (tfExtra1.value == '0' || tfExtra1.value > 10) {
		var errorDialog5 = Titanium.UI.createAlertDialog({
			title: 'Hol Up!',
			message: 'Must be 10% or less.'
		});
		errorDialog5.show();}
		if (tfExtra2.value == '0' || tfExtra2.value > 10) {
		var errorDialog6 = Titanium.UI.createAlertDialog({
			title: 'Hol Up!',
			message: 'Must be 10% or less.'
		});
		errorDialog6.show();}
		if (tfExtra3.value == '0' || tfExtra3.value > 10) {
		var errorDialog7 = Titanium.UI.createAlertDialog({
			title: 'Hol Up!',
			message: 'Must be 10% or less.'
		});
		errorDialog7.show();}
	else {
		var optionsMessage = "";
		
		if (e.source.id == 2) {
			//Adding the Percentage Grade
			var totalPercent = (((tfPOne.value + tfExtra1.value) * .25)  + ((tfPTwo.value + tfExtra2.value) * .25) + ((tfPThree.value + tfExtra3.value) * .4) + (tfPart.value * .1));// + (tfExtra1.value + tfExtra2.value + tfExtra3.value)
			Ti.API.info(totalPercent);
			optionsMessage = "Your grade is " + totalPercent + "%";
		}
		else {
			//Interest (I) = Principal (P) times Rate Per Period (r) times Number of Periods (n) / 12 
			var letterGrade = (tfAmount.value * (interestRate / 100) * numberMonths) / 12;
			var totalRepayments = Math.round(tfAmount.value) + totalInterest;
			Ti.API.info(totalRepayments);
			optionsMessage = "Total repayments on this loan equates to $" + totalRepayments;
		}
/*if (totalPercent <= 90)
'Your Grade is a B'
if (totalPercent <= 80)
'Your Grade is a C'
if (totalPercent <= 70)
'Your Grade is a D'
if (totalPercent <= 60)
'Your Grade is an F'
else 
'Your Grade is an A'*/
		//check our win3 autoShowChart boolean value first (coming from the switch on window3.js)
		if (win3.autoShowChart == true) {
		   openChartWindow();
		}
		else {
			var resultOptionDialog = Titanium.UI.createOptionDialog({
				title: optionsMessage,
				options: ['Show Chart', 'Close'],
				cancel: 1
			});
			resultOptionDialog.addEventListener('click', function(e){
				Ti.API.info('Button index tapped was: ' + e.index);
				if (e.index == 0) {
					openChartWindow();
				}
			});
			resultOptionDialog.show();}
		
	}
} 


Is This A Good Question/Topic? 0
  • +

Replies To: Grade Calculator JavaScript

#2 Kruithne  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 99
  • View blog
  • Posts: 442
  • Joined: 28-July 09

Re: Grade Calculator JavaScript

Posted 02 November 2012 - 02:15 AM

Hello there,

Firstly, I would suggest checking out switch statements (link) to make that monster IF statement a little clearer and more efficient.

Secondly, trying to form an application out of another is never a good idea and isn't the best practice to help you learn how things work, you end up just getting in a mess. I suggest starting from scratch and going one step at a time.

As always, feel free to ask for more assistance, but please provide a little more insight into what your issue is rather than just 'make it work'.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1