...

View Full Version : help middle aged (45) newbie



neilbigh101
06-08-2007, 06:53 PM
hi all, fairly new to pc`s(18 month`s) started to wonder how all the scripting works (God knows why?) bought Dummies JavaScript guide but cant make this work any idea`s thanking you in anticipation Neil


<HTML>
<HEAD>
<TITLE>
</TITLE>


<SCRIPT LANGUAGE = "JavaScript">

var userImput;

var userName;

var upperLimit = 20;

userInput = window.prompt('Please enter a number in the range 0 to ' <= upperLimit, '');

userNumber = parseFloat (userInput);

while ( (userNumber <= 1 || (userNumber >= upperLimit ));

{
userInput = window.prompt('Please re-enter - number should be in range 0 to <= upperLimit,'');

}
document.write('<BR>' + Your chosen number was ' + yourNumber');

</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>

javabits
06-08-2007, 07:20 PM
You had several variable names wrong. Also you need to make sure your strings have quotes at the beginning and end. You didn't parse the float inside the while loop. There was a semicolon in your while loop condition. You had some unmatched parentheses in the while loop condition too.

Also if you are using Firefox I would recommend using the Javascript Console in the Tools menu. It'll help track down a lot of these problems.



<HTML>
<HEAD>
<TITLE>
</TITLE>

<SCRIPT LANGUAGE = "JavaScript">
var userInput;
var userName;
var userNumber;
var upperLimit = 20;

userInput = window.prompt('Please enter a number in the range 0 to <= upperLimit', '');
userNumber = parseFloat (userInput);

while ( (userNumber <= 1) || (userNumber >= upperLimit ))
{
userInput = window.prompt('Please re-enter - number should be in range 0 to <= upperLimit','');
userNumber = parseFloat (userInput);
}

document.write('<BR>' + 'Your chosen number was ' + userNumber);

</SCRIPT>

</HEAD>
<BODY>

</BODY>
</HTML>


semper fi...

gary

Philip M
06-08-2007, 07:39 PM
javbits beat me to it!

Why parseFloat()? Surely you are asking for an integer number, so if the user enters (say) 12.3 you want to return 12.

Note that that accuracy is vital - userImput is not the same as userInput, and remember that JavaScript is case sensitive. Also unmatched quotes will cause the script to fail.

neilbigh101
06-09-2007, 10:49 AM
You had several variable names wrong. Also you need to make sure your strings have quotes at the beginning and end. You didn't parse the float inside the while loop. There was a semicolon in your while loop condition. You had some unmatched parentheses in the while loop condition too.

Also if you are using Firefox I would recommend using the Javascript Console in the Tools menu. It'll help track down a lot of these problems.



<HTML>
<HEAD>
<TITLE>
</TITLE>

<SCRIPT LANGUAGE = "JavaScript">
var userInput;
var userName;
var userNumber;
var upperLimit = 20;

userInput = window.prompt('Please enter a number in the range 0 to <= upperLimit', '');
userNumber = parseFloat (userInput);

while ( (userNumber <= 1) || (userNumber >= upperLimit ))
{
userInput = window.prompt('Please re-enter - number should be in range 0 to <= upperLimit','');
userNumber = parseFloat (userInput);
}

document.write('<BR>' + 'Your chosen number was ' + userNumber);

</SCRIPT>

</HEAD>
<BODY>

</BODY>
</HTML>


semper fi...

gary

hi Gary thank you for taking the time and trouble to respond to my problem, i seem to learn best by sort of idiot fashion dont what i`m following at the start but by following the idiot cards it normally sinks in, i know it sounds cheeky but would it be possible for you to either underline or if you would be so kind as to correct the mistakes i have made then i will have a working example to practice on i.e. change bits to see how it works or not in my case. Best regards Neil

_Aerospace_Eng_
06-09-2007, 10:52 AM
hi Gary thank you for taking the time and trouble to respond to my problem, i seem to learn best by sort of idiot fashion dont what i`m following at the start but by following the idiot cards it normally sinks in, i know it sounds cheeky but would it be possible for you to either underline or if you would be so kind as to correct the mistakes i have made then i will have a working example to practice on i.e. change bits to see how it works or not in my case. Best regards Neil

Can you not just compare the updated code with your old code? :confused:

neilbigh101
06-09-2007, 11:11 AM
Can you not just compare the updated code with your old code? :confused:
hi Aerospace didnt have any old code just tried to dive in and put all the seperate bit`s together know it sounds daft but that way eventually the penny does seem to drop, empahsis on eventually, any further hwlp would be hugely appreciated thank you, Neil

Philip M
06-09-2007, 12:13 PM
hi Aerospace didnt have any old code just tried to dive in and put all the seperate bit`s together know it sounds daft but that way eventually the penny does seem to drop, empahsis on eventually, any further hwlp would be hugely appreciated thank you, Neil

He means compare the code kindly provided by javabits with the code you posted originally.

neilbigh101
06-09-2007, 12:49 PM
sorry, just like they told me in school "must pay more attention" thank you all very much, it`s much appreciated best regards Neil

neilbigh101
06-09-2007, 02:34 PM
Cheers guy`s it works great, you make it look so easy?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum