Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    Sep 2012
    Posts
    15
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Getting error with debugger

    [Code:]
    Timestamp: 9/8/2012 11:30:59 PM
    Error: SyntaxError: illegal XML character
    Source Code:
    if(.01 || <1.00)
    -----------^
    [/Code]

    FireFox debugger doesn't like 1.00 or 1.0 or 1
    What I am trying to say is:
    .
    If it is 1¢ or less than $1.00

  • #2
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,968
    Thanks
    56
    Thanked 557 Times in 554 Posts
    you are making a comparison but giving the code nothing to compare it to. generally speaking (but not always), the left side will have a variable:

    Code:
    if(x==.01 || x<1)

  • Users who have thanked xelawho for this post:

    msNewbie (09-09-2012)

  • #3
    New Coder
    Join Date
    Sep 2012
    Posts
    15
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Entire script enclosed

    Quote Originally Posted by xelawho View Post
    you are making a comparison but giving the code nothing to compare it to. generally speaking (but not always), the left side will have a variable:

    Code:
    if(x==.01 || x<1)
    Dang! I forgot to say that I tried that too, sorry bout that!
    Here is the entire code.
    Everything works all the up to the last section where it declares winner or loser.
    Code:
    function main()  //program driver
    {	// This begins function main()
    
    // This section tells me what the variables are
    
    	var pennies = 0;
    	var nickles = 0;
    	var dimes   =0;
    	var quarters = 0;
    	var halfDollars = 0;
    	var dollars = 0;
    	var t       = 0;
    
    // This section will let the user be prompted for the amount of coin.
    
    	pennies = parseFloat(prompt("Enter how many pennies you have:", ""));
    	nickles = parseFloat(prompt("Enter how many nickles you have:", ""));	
    	dimes = parseFloat(prompt("Enter how many dimes you have:", ""));	
    	quarters = parseFloat(prompt("Enter how many quarters you have:", ""));
    	halfDollars = parseFloat(prompt("Enter how many half dollars you have:", ""));	
    	dollars = parseFloat(prompt("Enter how many dollars you have:", ""));
    
    	t = .01 * pennies + .05 * nickles + .10 * dimes + .25 * quarters + .5 * halfDollars + 1 * dollars;
    		
    // Shows total coins
    	function outputDeclairAmountTotal(pennies, nickles, dimes, quarters, halfDollars, dollars)
    	{
    	alert("Pennies: " + pennies + "\n" +
    	      "Nickles: " + nickles + "\n" +
    		  "Dimes: " + dimes + "\n" +
    		  "Quarters: " + quarters + "\n" +
    		  "Half Dollars: " + halfDollars + "\n" +
    		  "Dollars: " + dollars + "\n" +
    	      "Caculated amount: " + t.toFixed(2));
    	}
    		  
    // This will give the results of the game. 
    // Equal to 1¢ or less than $1.00 = Sorry! You lose! You have less than one dollar.
    // Over one dollar = Sorry! You lose! You have more that one dollar.
    // If no coins were put in then = No coins entered.
    // If you won then = Congratulations! You win!
    	function 
    	if(t==.01 || x<1)
    		{
    			alert("Sorry! You lose! You have less than one dollar.")
    		}
    		
    	else if(t== >1)
    		{
    			alert("Sorry! You lose! You have more than one dollar.") 
    		}
    	
    	else (1)
    	{
    	alert("Congratulations! You win! You have exactly one dollar.")
    	}
    			 
    		   
    }	//	This ends function main()
    Last edited by msNewbie; 09-09-2012 at 06:31 AM.

  • #4
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    Code:
    else if(t== >1)
    this syntax is incorrect, and
    Code:
    else (1)
    will always be true.

    You should be able to fix this by reading any guide to comparison operators.
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • Users who have thanked AndrewGSW for this post:

    msNewbie (09-09-2012)

  • #5
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    Code:
    function 
    	if(t==.01 || x<1)
    		{
    			alert("Sorry! You lose! You have less than one dollar.")
    		}
    I would say the error is on the line preceding the test.

  • Users who have thanked Logic Ali for this post:

    msNewbie (09-10-2012)

  • #6
    New Coder
    Join Date
    Sep 2012
    Posts
    15
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Angry

    Quote Originally Posted by AndrewGSW View Post
    Code:
    else if(t== >1)
    this syntax is incorrect, and
    Code:
    else (1)
    will always be true.

    You should be able to fix this by reading any guide to comparison operators.
    I read the page and I was up until 04:30 doing it in almost every combination that I could figure. Then I wind up waking up out of frustration and trying more (or probably duplicate of this morning) and it still won't work.
    I tried with the && . I tried without the && .
    I tried spaces. I tried no spaces.
    I tried parenthesis. I tried no parenthesis.
    I even tried just <.01 and I catch hell from the debugger.
    No matter WHAT I tried it just keeps giving me errors and won't even start the program. Grrr! Am I thinking the wrong way? Obviously but HOW am I thinking wrong? I don't want to keep guessing I want to understand and be able to think the solution out the right way.
    Have you tried to see if you could get this program to work at all the right way?
    WTH is the >>>illegal XML character<<< anyways?
    This was my last shot at the bottom section and I got this error:
    Code:
    Error: SyntaxError: illegal XML character
    Line: 43, Column: 9
    Source Code:
    if (t=(<1&&>99)) 
    --------^
    Even on the comparison operator's page they have this:
    Code:
    14.if (hour<6 && hour>12) //&& logically compares truth of two values
    15.document.write(“<h1>Good afternoon!!</h1>”);
    Last edited by msNewbie; 09-09-2012 at 01:41 PM.

  • #7
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    As Logic Ali points out there is an error before it gets to the if statement. You haven't created a function, although you've started one:

    Code:
    function  // complete this definition, or delete it, as appropriate
    	if(t==.01 || x<1)
    		{
    			alert("Sorry! You lose! You have less than one dollar.")
    		}
    		
    	else if(t > 1)    // should you be checking x or t?
    		{
    			alert("Sorry! You lose! You have more than one dollar.") 
    		}
    	
    	else if (t == 1)
    Once you've corrected all this you'll need to account for rounding errors. That is, t might end up as 1.00000001.
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • Users who have thanked AndrewGSW for this post:

    msNewbie (09-10-2012)

  • #8
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,982
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    If rounding errors are an issue you can do

    Code:
    var x = 1.0000001;
    x = x.toFixed(2);  // x is now a string value
    x = Number (x);  // back to a number
    alert (x);

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • Users who have thanked Philip M for this post:

    msNewbie (09-10-2012)

  • #9
    New Coder
    Join Date
    Sep 2012
    Posts
    15
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by AndrewGSW View Post
    As Logic Ali points out there is an error before it gets to the if statement. You haven't created a function, although you've started one:

    Code:
    function  // complete this definition, or delete it, as appropriate
    	if(t==.01 || x<1)
    		{
    			alert("Sorry! You lose! You have less than one dollar.")
    		}
    		
    	else if(t > 1)    // should you be checking x or t?
    		{
    			alert("Sorry! You lose! You have more than one dollar.") 
    		}
    	
    	else if (t == 1)
    Once you've corrected all this you'll need to account for rounding errors. That is, t might end up as 1.00000001.
    ==============
    ++++++++++++++
    ==============

    If you look at the complete code above I took your advice.
    The top section has been tested and works great.
    This is the bottom section that refuses to work.
    The function line has been removed.

    Here is the change I made and I am STILL thinking wrong somehow.
    I realize that I have only just started learning code for only two weeks but I feel that I am missing something even after reading the site someone gave me and this is due 9/11/12.
    Code:
    	if (t=(<1&&>99))
    		{
    			alert("Sorry! You lose! You have less than one dollar.");
    		}
    		
    	if (t=(<1.01&&>50))
    		{
    			alert("Sorry! You lose! You have more than one dollar.");
    		}
    	
    	if (t= (1))
    		{
    			alert("Congratulations! You WIN! You have exactly one dollar.");
    		}
    }
    Has anyone tried to get this script to work on their computer?

  • #10
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    Code:
    if (t=(<1&&>99))
    This is more wrong than the original code! You don't seem to have read or understood the advice, and code, given in previous posts.

    Code:
    var wibble = 50;
    if (wibble >= 1 && wibble <= 100) {
        alert('Yes it is somewhere between 1 and 100!');
    }
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •