Jump to content

Number range


ibrahimjan

Recommended Posts

I do not have experience using java, any help on this post is appreciated, what I would like is to enter a value between 1-50 in the var n=5 then if the number is in that range it should write (35), that's it.Please have a look at my attempt at this, any correction is appreciated.<script type="text/javascript"><!--function validate(){var n=5;if (n<1 || n >50) {document.write(35);}//--></script>

Link to comment
Share on other sites

I do not have experience using java, any help on this post is appreciated, what I would like is to enter a value between 1-50 in the var n=5 then if the number is in that range it should write (35), that's it.Please have a look at my attempt at this, any correction is appreciated.<script type="text/javascript"><!--function validate(){var n=5;if (n<1 || n >50) {document.write(35);}//--></script>
function validate(n){ if(n<1 || n>50){ document.getElementById('number').innerHTML = '35'; }}</script></head><body><form name="myform"><input type="text" name="num" /><input type="button" value="click" onclick="validate(myform.num.value);" /></form><p id="number"></p></body>
Link to comment
Share on other sites

First, people don't enter numbers on a page, everything anyone types is regular text. You need to convert it to a number if you want to test it like a number. You can use parseInt for that:

function validate(n){  n = parseInt(n, 10);  if (isNaN(n))  {	alert('You must enter a number');	return false;  }  ...

Second, you're still checking if the number is less than 1 or greater than 50:if(n<1 || n>50){You would read that like "if n is less than 1 or n is greater than 50".

Link to comment
Share on other sites

My mother taught me this:Small numbers don't like being small. They want to be bigger. The way to grow bigger is to eat a larger number. To eat a larger number, you have to open your mouth wide and point your open mouth at the bigger number.little number wants to eat < bigger number, who wants to eat < even bigger numberIt wasn't exactly a calculus lesson, but I've never forgotten it.

Link to comment
Share on other sites

My mother taught me this:Small numbers don't like being small. They want to be bigger. The way to grow bigger is to eat a larger number. To eat a larger number, you have to open your mouth wide and point your open mouth at the bigger number.little number wants to eat < bigger number, who wants to eat < even bigger numberIt wasn't exactly a calculus lesson, but I've never forgotten it.
:) I think one of my math teachers (I think algebra) taught us a very similar lesson...
Link to comment
Share on other sites

My mother taught me this:Small numbers don't like being small. They want to be bigger. The way to grow bigger is to eat a larger number. To eat a larger number, you have to open your mouth wide and point your open mouth at the bigger number.little number wants to eat < bigger number, who wants to eat < even bigger numberIt wasn't exactly a calculus lesson, but I've never forgotten it.
does that really help? :)edit: to the OP, just clarify, you are using javascript, not Java.
Link to comment
Share on other sites

does that really help? :)edit: to the OP, just clarify, you are using javascript, not Java.
Thank you all for your input into this matter, i am trying to use Java script to make this work. What I don't need is a form to pass the verbal, I will change the values later to use ASP connected to a database. I am trying to get the math correct first.Maybe I have confused all with my attempt to the js script, please fell free to correct me,What I need is a simple script to do the following.A value is returned from the database, this can be represented by the letter n.this value then is compared against a range of 1-50,if it lays within this range please print the number 35.it is as simple as that, please keep it simple and nothing to complicated, ideally few lines to do this job.once agin I thank all for there input
Link to comment
Share on other sites

The first thing is to change this expression:(n<1 || n>50)The letters are correct. The numbers are correct. The parentheses are correct. (EDIT see next 2 posts). Look at Post #2 for your answer and think about which symbols need to be changed, and how to change them.

Link to comment
Share on other sites

Let's talk about this in human words, and then see how the human words turn into programming symbols.n is the number you want to test.to pass your test, these things must be true:n must be greater than or equal to 1 (what is the symbol for "greater than or equal to"?)and (what is the symbol for "and"?)n must be less than or equal to 50 (what is the symbol for "less than or equal to"?)This is enough information to write your expression in programming symbols.---To be fair, I cheated a little on this. I chose those specific human words because I already knew what programming symbols were available.In your original post, you used the word "between." Unfortunately, there is no symbol that means "between." So we have to think about other symbols.I do know that there are symbols for "greater than" and "less than". I also know that if a number is "between" 2 other numbers, than it must be greater than one and less than the other. If it is okay for the number to be equal to the outside numbers, then we must change the symbols to include "equal." So now we use the words "greater than or equal to" and "less than or equal to."

Link to comment
Share on other sites

Let's talk about this in human words, and then see how the human words turn into programming symbols.n is the number you want to test.to pass your test, these things must be true:n must be greater than or equal to 1 (what is the symbol for "greater than or equal to"?)and (what is the symbol for "and"?)n must be less than or equal to 50 (what is the symbol for "less than or equal to"?)This is enough information to write your expression in programming symbols.---To be fair, I cheated a little on this. I chose those specific human words because I already knew what programming symbols were available.In your original post, you used the word "between." Unfortunately, there is no symbol that means "between." So we have to think about other symbols.I do know that there are symbols for "greater than" and "less than". I also know that if a number is "between" 2 other numbers, than it must be greater than one and less than the other. If it is okay for the number to be equal to the outside numbers, then we must change the symbols to include "equal." So now we use the words "greater than or equal to" and "less than or equal to."
Got it working thanks to dsonesuk, what I need to do now is add the results together and get the answer to = 80 please have a look at the script and see if you can help. Thank you all.<script type="text/javascript">/*<![CDATA[*//*---->*/function validate(){var n=450;if (n>=1 && n <=520) {document.write(35);}{var p=600;if (p>=521 && p <=700) {document.write(45);}}}validate();/*--*//*]]>*/</script>
Link to comment
Share on other sites

Man, we're trying to teach you and he's sending you code through PM, huh? Well, I guess I could try to explain what you need to do and how to do it, but screw that, I'm sure he'll just send you the code again. Saves us both time.
Sorry all to bother you with my lack of knowledge in this subject, I have a deadline and my boss is killing me on this, please your urgent help is appreciated,Justsomeguy, I appreciate the lessons I'd love to learn from you all, but at the moment there is no time, will definitely look in more depth for the future. Once agin thanks to all for there contribution on this matter.
Link to comment
Share on other sites

Sorry all to bother you with my lack of knowledge in this subject, I have a deadline and my boss is killing me on this, please your urgent help is appreciated,Justsomeguy, I appreciate the lessons I'd love to learn from you all, but at the moment there is no time, will definitely look in more depth for the future. Once again thanks to all for there contribution on this matter.
ah, you can just wait for dsonesuk. Most of us here like to teach, not just give out the answers. If you don't find the answer, hopefully your teacher boss can give you an extension and we can teach you how to do it.
Link to comment
Share on other sites

Whoa, whoa! again get your facts right, I never just sent the solution through PM, I did not even know he had posted a topic until afterwards, he contacted me through PM, i provided the solution plus an explanation why his code would not work, ie greater than, less than, OR compared to AND. I'm sorry if i got you little girls panties in a twist, and you are now having one of you girlie fits, but don't blame me! and get a life!.

Link to comment
Share on other sites

Ok all I think I am in the wrong place for help, I don't mean to stir trouble between members DSONESUK did not provide me with the code, he explained to me where I was going wrong, as you all have failed to do so, I don't have time for this, I would love to learn from you all, but I just don't have the time or to do that now, if you can help that's perfect, if not let me know so I can look at other sources for help. Once again thank you for your help and time.

Link to comment
Share on other sites

Ok all I think I am in the wrong place for help, I don't mean to stir trouble between members DSONESUK did not provide me with the code, he explained to me where I was going wrong, as you all have failed to do so, I don't have time for this, I would love to learn from you all, but I just don't have the time or to do that now, if you can help that's perfect, if not let me know so I can look at other sources for help. Once again thank you for your help and time.
If you can only say that with a straight face, then I don't see how anyone else could even think of wanting to help you further. Did you not even read the other posts in this thread?
First, people don't enter numbers on a page, everything anyone types is regular text. You need to convert it to a number if you want to test it like a number. You can use parseInt for that:
function validate(n){  n = parseInt(n, 10);  if (isNaN(n))  {	alert('You must enter a number');	return false;  }  ...

Second, you're still checking if the number is less than 1 or greater than 50:if(n<1 || n>50){You would read that like "if n is less than 1 or n is greater than 50".

The first thing is to change this expression:(n<1 || n>50)The letters are correct. The numbers are correct. The parentheses are correct. (EDIT see next 2 posts). Look at Post #2 for your answer and think about which symbols need to be changed, and how to change them.
Let's talk about this in human words, and then see how the human words turn into programming symbols.n is the number you want to test.to pass your test, these things must be true:n must be greater than or equal to 1 (what is the symbol for "greater than or equal to"?)and (what is the symbol for "and"?)n must be less than or equal to 50 (what is the symbol for "less than or equal to"?)This is enough information to write your expression in programming symbols.---To be fair, I cheated a little on this. I chose those specific human words because I already knew what programming symbols were available.In your original post, you used the word "between." Unfortunately, there is no symbol that means "between." So we have to think about other symbols.I do know that there are symbols for "greater than" and "less than". I also know that if a number is "between" 2 other numbers, than it must be greater than one and less than the other. If it is okay for the number to be equal to the outside numbers, then we must change the symbols to include "equal." So now we use the words "greater than or equal to" and "less than or equal to."
Link to comment
Share on other sites

...he explained to me where I was going wrong, as you all have failed to do so...
I beg to differ...
You're checking if the value is less than 1 or greater than 50. It should be greater than or equal to 1, and less than or equal to 50.
people don't enter numbers on a page, everything anyone types is regular text. You need to convert it to a number if you want to test it like a number. You can use parseInt for that:
function validate(n){  n = parseInt(n, 10);  if (isNaN(n))  {	alert('You must enter a number');	return false;  }  ...

The first thing is to change this expression:(n<1 || n>50)The letters are correct. The numbers are correct. The parentheses are correct....Look at Post #2 for your answer and think about which symbols need to be changed, and how to change them.
These all look like helpful posts to me...EDIT: looks like scientist had the same thought.
Link to comment
Share on other sites

:) Yeah, it's like ESPN or something...
It's seems to be recently, a lot of people asking for "help", then just want the answers, get all the help they need, get mad its not "just" the answer, get an answer, and then came back asking for more help to do more stuff to their code, when if they had just taken a couple of hours to learn in the first place, they could probably already be working on solving the next part of their code. It must be nice to not have the sense of urgency to have to learn and figure something out for yourself (albeit with some help along the way), I know my day job would be a lot more relaxing.
Link to comment
Share on other sites

Depends on how we define "help" doesn't it? If you want someone to rewrite your code all the time, yes, this is probably the wrong place. If you want to learn what your code does and how to improve it yourself, we're pretty good at that.FWIW, I hope you are not employed as an actual programmer in any language. The arithmetical operators are pretty much the same in any language, and they are usually taught in the first week of any programming class, and the first chapter of most programming books. When I laid out my explanation in Post 12, I honestly believed I was writing for a 12-year-old. THAT's how basic the problem was.JSG, I hope you're thinking of nuking this thread soon.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...