-
March 28th, 2005, 06:59 PM
#1
I lost this bet and don't know why
Heres the deal ........
I made a bet with a friend that I could write a working javaScript that asked the user for 2 numbers and then displayed the sum, differance, product and quotient of the 2 integers. Its a very easy script but the catch was I had to add quotes for readability and get it done in 3 minutes or less.
I got it done in less then 3 minutes but I still lost the bet because, for some reason it didn't work and now that I have paid my losers wages to my mate I'm trying to debug this thing and as easy of a script that it is ...... I can't see what I did wrong.
Its blowing my mind, so here is my script ........... WHATS WRONG WITH IT???
Code:
<html>
<head>
<title>Quick JavaScript</title>
<script type = "text/javascript">
var firstNumber, //first string entered by user
secondNumber, //second string entered by user
number1, //first number to use
number2, //second number to use
sum, //sum of number1 and number2
product, //product of number1 and number2
differance, //differance of number1 and number2
quotient; //quotient of number1 and number2
//read first number from user as a string
firstNumber = window.prompt("Enter first integer", "0");
//read second number from user as a string
secondNumber = window.prompt("Enter second integer", "0");
//converts numbers from strings to integers
number1 = parseInt(firstNumber);
number2 = parseInt(secondNumber);
//performs operations
sum = number1 + number2;
product = number1 * number2;
differance = number1 - number2;
quotient = number1 / number2;
//displays output of operations
document.writeln("The sum of " + number1 "and " + number2 + "is " + sum);
document.writeln("The product of " + number1 "and " + number2 + "is " + product);
document.writeln("The differance of " + number1 "and " + number2 + "is " + differance);
document.writeln("The quotient of " + number1 "and " + number2 + "is " + quotient);
</script>
</head>
<body>
</body>
</html>
The prompt windows doesn't even come up so it is something in that part of the script.
I know it is probably something blatantly obvious, but my eyes aren't catching it, maybe someone heres eyes will - Im dumbfounded.
"In most gardens they make the beds too soft - so that the flowers are always asleep" - Tiger Lily
-
March 29th, 2005, 05:59 AM
#2
Well after a few hours - I have noticed that many have viewed this post but noone replied - anyways ........... I finally worked it out - not enough "+" signs in the 'document.writeln...' statements ......... go figure
One thing I do not understand though that maybe someone can clarify is:
If the problem was in the 'document.writeln...' statement, why did that hinder the 'window.prompt...' statement from executing?
Shouldn't the first statements have executed and then just not print the outcome?
"In most gardens they make the beds too soft - so that the flowers are always asleep" - Tiger Lily
-
March 29th, 2005, 01:55 PM
#3
it was parsed, a flaw was found and the code was never executed as a safety measure.
With all the subtlety of an artillery barrage / Follow blindly, for the true path is sketchy at best. .: Bring OS X to x86!:.
Og ingen kan minnast dei linne drag i dronningas andlet den fagre dag Då landet her kvilte i heilag fred og alle hadde kjærleik å elske med.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|