Results 1 to 3 of 3

Thread: I lost this bet and don't know why

  1. #1
    Senior Member IcSilk's Avatar
    Join Date
    Aug 2001

    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???

    	<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);
    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

  2. #2
    Senior Member IcSilk's Avatar
    Join Date
    Aug 2001
    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

  3. #3
    Now, RFC Compliant! Noia's Avatar
    Join Date
    Jan 2002
    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