www.webdeveloper.com
Results 1 to 3 of 3

Thread: Little help with JavaScript please

  1. #1
    Join Date
    May 2013
    Posts
    2

    Little help with JavaScript please

    Hi guys,

    I have just a simple code that I can't explain why is not working - can someone please take a look ?

    Code:
    <html>
    <head>
    <title>Basic JavaScript example</title>
    <style type='text/css'>
    </style>
    <script type='text/javascript'>
    function try() {
    
    var car = new Object();
    car.make = "German";
    car.model = "Opel";
    car.engine = 230;
    car.tsped = 320;
    car.csped = 0;
    
     car.accelerate = function(){
     if(this.csped <= 315)
      {
      this.csped +=5;
      }
     }
     car.decelerate = function(){
     if(this.csped >= 5)
      {
      this.csped -=5;
      } 
     }
    car.toString = function()
    	{
    		alert(this.make + " model: " + this.model + " engine capacity: " + this.engine + " current speed: " + this.csped);
    	}
     car.toString;
     car.accelerate();
     car.toSting;
     car.accelerate();
     car.toString;
    }
    
    </script>
    </head>
    <body>
    
    <input type="button" value="Go!" onclick="try()" /><br >
    
    </body>
    </html>

  2. #2
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    Quote Originally Posted by clicka View Post
    Hi guys,

    I have just a simple code that I can't explain why is not working -
    Use the error console. Its output:

    SyntaxError: missing { before try block

    try
    is a reserved word.

    Missing parentheses.
    Code:
    car.toString();
     car.accelerate();
     car.toSting();
     car.accelerate();
     car.toString();
    Last edited by Logic Ali; 05-16-2013 at 05:09 PM.
    Where used, return should be executed unconditionally and always as the last statement in the function.

    That's my signature, it's not part of the damn post!

  3. #3
    Join Date
    May 2013
    Posts
    2
    Thank you very much for your response - it fixed the problem

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles