Input problem

Just about finished

Page 1 of 1

8 Replies - 690 Views - Last Post: 17 December 2009 - 02:11 PM

#1 slicko9  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 17-December 09

Input problem

Posted 17 December 2009 - 01:16 PM

I have a project due for class tonight, i wrote the code, have it completely working just the way that it should.
I overlooked one step in the assignment however.

I need to ask the user for input about how many homework, project, and exam they have completed and then set the array equal to that. I wrote the code based on the number of assignments in class and do not know how to change it to make it work by input. Could someone point me in the right direction please?

<!DOCTYPE HTML PUBLIC >
<html>
<body>
<h1>  Project 4  </h1>
<head>
<script type="text/javascript">



function GetValidInput(promptString) 
{
  var input
  input = parseInt( prompt( promptString));
  if(input < -1 || isNaN(input) || input > 106) 
	{
	alert("You did not receive that as a grade, Please enter a grade between 0 and 105.");
	input = GetValidInput(promptString);
	}
  return input;
}
		   

 
function average(number) 
{
  Sum = 0;
  for (var i = 0; i < number.length; i++)
  {
	Sum += number[i];
  }
  return (Sum/number.length);
}



var hwArray = new Array();

for(var i=0;i<3;i++) 
{
  hwArray[i] = GetValidInput("Enter your homework score");
  if(hwArray[i]==-1)
  break;
}
var hwAverage = average(hwArray);

var projArray = new Array();
for(var i=0;i<4;i++) 
{
  projArray[i] = GetValidInput("Enter your project score");
  if (projArray[i]==-1)break;
}
var projectAverage = average(projArray);

var examArray = new Array ();
for(var i=0;i<3;i++) 
{
  examArray[i] = GetValidInput("Enter your exam score");
  if (examArray[i]==-1)break;
}

var examAverage = average(examArray);


Grade = average([hwAverage,projectAverage,examAverage]);


if(Grade >= 90) 

	{ 
	alert ("You got a A!"); 
	}
else if(Grade >= 80 && Grade <= 89.99)

   { 
   alert ("You got a B!"); 
   }
else if(Grade >=70 && Grade <= 79.99)
	{ 
	alert ("You got a C"); 
	}
else if(Grade >= 60 && Grade <= 69.99)
	{ 
	alert ("You got a D"); 
	}
else
	{ 
	alert ("You got a F"); 
	}
	
  
 
  
</script>

</body>
</html>



Is This A Good Question/Topic? 0
  • +

Replies To: Input problem

#2 cnampheonix  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 63
  • Joined: 03-December 09

Re: Input problem

Posted 17 December 2009 - 01:31 PM

Just go to
http://www.dreaminco...topic145679.htm

That is where you copy and pasted stuff to make your code isn't it?

Hint hint *plagiarize*

If you didn't and somehow it just looks almost exactly like my code
My sincerest apologies
Was This Post Helpful? 0
  • +
  • -

#3 slicko9  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 17-December 09

Re: Input problem

Posted 17 December 2009 - 01:34 PM

View Postcnampheonix, on 17 Dec, 2009 - 12:31 PM, said:

Just go to
http://www.dreaminco...topic145679.htm

That is where you copy and pasted stuff to make your code isn't it?

Hint hint *plagiarize*

If you didn't and somehow it just looks almost exactly like my code
My sincerest apologies



i didnt plagiarize. i do see why it looks that way though. I'll delete it all, i dont want any trouble with the professors. Can you help me with the problem? I'm on campus if you are too?
Was This Post Helpful? 0
  • +
  • -

#4 cnampheonix  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 63
  • Joined: 03-December 09

Re: Input problem

Posted 17 December 2009 - 01:42 PM

prompt the user for the amount and change that into a variable
You could then use that to set the amount of times the "homework score" question is asked
Thats the way I did it, theres probably an easier way or something, but Im still a novice when it comes to javascript
Was This Post Helpful? 0
  • +
  • -

#5 slicko9  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 17-December 09

Re: Input problem

Posted 17 December 2009 - 01:52 PM

View Postcnampheonix, on 17 Dec, 2009 - 12:42 PM, said:

prompt the user for the amount and change that into a variable
You could then use that to set the amount of times the "homework score" question is asked
Thats the way I did it, theres probably an easier way or something, but Im still a novice when it comes to javascript


so am i,
are you taking 201 in the spring?

also, i think that if you take the input from the user and put that in as the argument when creating the array it will create the array to be that length.
Was This Post Helpful? 0
  • +
  • -

#6 cnampheonix  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 63
  • Joined: 03-December 09

Re: Input problem

Posted 17 December 2009 - 01:52 PM

Yes
Was This Post Helpful? 0
  • +
  • -

#7 slicko9  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 17-December 09

Re: Input problem

Posted 17 December 2009 - 01:55 PM

did you see what i said about hte length of the array being intialized by the argument?
Was This Post Helpful? 0
  • +
  • -

#8 cnampheonix  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 63
  • Joined: 03-December 09

Re: Input problem

Posted 17 December 2009 - 02:04 PM

Yes isnt that what you want?
I have it so that the array will be at that length but it loops so that I can put what I want into each section

btw. you forgot to put in -1 to quit since you have that
hw == -1
break

This post has been edited by cnampheonix: 17 December 2009 - 02:05 PM

Was This Post Helpful? 0
  • +
  • -

#9 slicko9  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 17-December 09

Re: Input problem

Posted 17 December 2009 - 02:11 PM

View Postcnampheonix, on 17 Dec, 2009 - 01:04 PM, said:

Yes isnt that what you want?
I have it so that the array will be at that length but it loops so that I can put what I want into each section

btw. you forgot to put in -1 to quit since you have that
hw == -1
break


i didnt think that we needed the sentintel
also, do we need to multiply the homework by the percentage?
and same with the projects and exams?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1