Ok hi, I'm brand new here and I hope I can get some help. I'm stuck on an assignment in my intro to scripting class. I am to:

"write a small web page that uses JavaScript to prompt the user for an integer. Verify that they have given you a valid number (i.e. not NaN). If they have entered an invalid value, keep prompting them until they give you a valid number (use a loop for this). Once you have a number, display the sum of all integers that are not the user-supplied number. (For instance, if I entered the value 5, I would see the sum of all integer numbers that are not 5)."

All I can infer from the assignment description is that the user input will be some sort of variable, and apparently "parseInt" or "parseFloat" will somehow be used to validate whether or not the user input is an integer(correct me if I'm wrong). I understand the use of a loop to repeat the process until a valid integer is given, but I guess where I
am stuck at is: what the exact variables will be, how to validate an integer, and how to call upon all other integers to add them up. If I could deduct the preceding, I think I could do the rest fine.

The sum of all integer numbers that are not the number? All? I'm no mathematician, but I think it can be shown that the answer would be the negative of the number (if you selected 5 the answer would be -5).

I suspect, though, that there is an error in the question.

Not one shred of evidence supports the notion that life is serious. eternal.co.za - code, thoughts, rants and raves f1rivals.net - formula 1 forums, and, hopefully, soon, prediction game

You could perhaps interpret the problem as being the sum of all integers that can be represented by a 8-bit, 16-bit or 32-bit int (signed or unsigned).

Not one shred of evidence supports the notion that life is serious. eternal.co.za - code, thoughts, rants and raves f1rivals.net - formula 1 forums, and, hopefully, soon, prediction game

"Now that everyone has suffered a bit I'll pass along a hint or two if necessary.

First hint: Integers come in both positive and negative values.
- Well, except for that pesky zero, I think it only comes in negative

I am not offering this hint because I wish to dissuade anyone from visiting. Far from it! Please feel free to stop by and get help on this or any assignment. I can usually do more good for you during a 20 minute office visit than I can with a dozen e-mail exchanges.

Of course, you still need to try to solve things on your own, and I do want you to e-mail (or even post!) your questions. If that kind of communication seems to be getting you nowhere though, then it is time for an on-campus intervention."

"Are you ready? Here is hint number 2:

An integer variable can only store a number within a range of possible values.

In other words, the variable cannot store just any integer value. There is a largest possible integer and a smallest possible integer which can be stored."

Okay, which is what I was getting at in my previous post. So we're talking signed ints, let's say the common 32-bit, which can store numbers in the range from –2,147,483,648 to 2,147,483,647. Now every number in the negative range has a positive partner (which cancels it) except –2,147,483,648. Let's say the user specifies a number x then the answer is –2,147,483,648 - x. If x is positive then the answer cannot be stored in a 32-bit int (since it will be less than the largest negative number that can be stored). Fortunately, JavaScript doesn't actually use 32-bit ints to store numbers, and will not show any signs of breaking.

Not one shred of evidence supports the notion that life is serious. eternal.co.za - code, thoughts, rants and raves f1rivals.net - formula 1 forums, and, hopefully, soon, prediction game

"Hmm, hint number 2 may not have been as clear as I had hoped. I'll add a bit more information to it.

If an integer variable were one byte long (it is not, this is just a hypothetical), then the range of possible values would be -128 to 127. That range would then be "all the possible integer values" that the variable could store. What would the sum of all those possible integers be?"

The number is stored as base 2, and a byte is 8 digits long, and the first digit is positive or minus. But two different people have given you the answer, in two totally different ways.
byte example = 5;
1 2 3 4 5 6 7 8
+/- 64 32 16 8 4 2 1
For an integer it is 32 digits.

"Hmm, hint number 2 may not have been as clear as I had hoped. I'll add a bit more information to it.

If an integer variable were one byte long (it is not, this is just a hypothetical), then the range of possible values would be -128 to 127. That range would then be "all the possible integer values" that the variable could store. What would the sum of all those possible integers be?"

I thought to myself: By that logic wouldn't the sum of the integers be the same value given by the user?

Yeah, I did. After adding everything from -10 to 10 together you get -10 again but my teacher said I'm still not quite right so then I asked if the answer is: The value given by the user will be returned negative or be returned the same if it's already negative to begin with. I'm still waiting for a response.

This is what I have:

<script type = "text/javascript">
<!--
var integer, //acceptable integer
user; //integer entered by user

Oh yeah, I forgot to add, it only loops twice and if it loops and then a valid value is input, the prompt goes away but the message isn't displayed (sorry I'm a total beginner) *scratches head*.