Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

defining weight?

Status
Not open for further replies.

f1girl2

Vendor
Dec 31, 2007
1
GB
I am a newbie to java and i dont understand why i am recieving an error saying that the "weight is undefined" on line 8

could anyone help?

<HTML>
<HEAD>Egg Sizes
<TITLE>A program for classifying eggs by size var weight</TITLE>
<SCRIPT LANGUAGE="JavaScript"
type="text/javascript">

// The weight of the egg weight = window.prompt('Please enter the weight of the egg in grams','');
document.write('The weight of the egg is ' + weight + ' g.');// Confirming the input //
if('The weight of the egg < 53g')
{
document.write('It is a Small egg.')
}
else
{
if('The weight of the egg 53g < 63g')
{
document.write('It is a Medium egg.')
}
else
{
if('The weight of the egg 63g < 73g')
{
document.write('It is a Large egg.')
}
else
{
if('The weight of the egg > 73g')
{
document.write('It is a Very large egg.')
}
}
}
document.write('Thank you for using this program.');
}
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>
 
You didn't define it

--Dan
Whenever you find yourself on the side of the majority, it is time to pause and reflect.
Mark Twain
 
Code:
// The weight of the egg [!](there should be a carriage return here)[/!]weight = window.prompt('Please enter the weight of the egg in grams','');
document.write('The weight of the egg is ' + weight + ' g.');// Confirming the input //


Just so you know, you're not supposed to post homework in the forums. Next time you have a question like this go ask your teacher.

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
You're going to need some more help with the programming because there are several other errors in the code that will prevent it from working.

Lee
 
The first clue that you are a newbie is that you confused JavaScript with Java. That is like confusing Pascal with Fortan.


Einstein47 (Starbase47.com)
“Never put both feet in your mouth at the same time.
Because then you won't have a leg to stand on.“

- Unknown
 
f1girl2, when you downloaded this assignment you should have read a warning about submitting work that was not your own. Tutors can read these forums too!

You've somehow managed to lose a carriage return from the supplied file. However, there are more serious things wrong than that. You need to understand what it means to enclose part of the text in quotes, for example. There's really no substitute for working step by step through the course material, doing ALL the exercises. That way you soon discover you haven't understood something, and you can go back and have another look.

If you're really stuck, the person to ask is your tutor - or you could try your regional M150 conference.
 
I see that you know very little about JavaScript.
Don't make it more complicated than it is..
Basicly this is how it could be done:

Code:
var egg_w = window.prompt('Please enter the weight of the egg in grams','');
   if (egg_w && parseInt(egg_w)) {
   egg_w = parseInt(egg_w);
   document.write('The weight of the egg is '+egg_w+'g.<br>');
      if(egg_w < 53) {document.write('It is a Small egg.<br>');}
      else if (egg_w < 63) {document.write('It is a Medium egg.<br>');}
      else if (egg_w < 73) {document.write('It is a Large egg.<br>');}
      else {document.write('It is a Very large egg.<br>');}
   }
   else {document.write('You didn\'t enter the weight!');}
document.write('Thank you for using this program.');

This would output (if weight is defined correctly by user):

The weight of the egg is ##g.
It is a Xxx egg.
Thank you for using this program.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top