• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Help finding a "SyntaxError: Unexpected Token"

 
Greenhorn
Posts: 6
Mac Chrome Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have recently started trying to learn Java. I've been using Codecademy.com because word of mouth has told me that that is the best. I am stuck on the part with the Rock, Paper, Scissors game (where the computer chooses one and you choose one and it tells you the winner). I am on part 8/9, and am done with the meat of the code. I just have one problem, where whenever i try to finish it, it says "SyntaxError: Unexpected Token". I have methodically erased all parentheses and brackets one-by-one, in case i had an extra one somewhere. it hasn't worked. If one of you could look at my code for me and tell me what was wrong, that'd be great.

 
Ranch Hand
Posts: 76
3
IntelliJ IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This looks like JavaScript. Are you sure what you are learning is Java?
 
Huang Xing
Greenhorn
Posts: 6
Mac Chrome Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh lord it is Javascript. I'm not sure what the difference is but it can't be good. I thought that Javascript was just the technical term for Java.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JavaScript and Java are two different programming languages, which happen to have the word "Java" in common in their names - because of historical reasons.

Java and JavaScript are just as related as ham and hamster...
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
look http://www.htmlgoodies.com/beyond/javascript/article.php/3470971/Java-vs-JavaScript.htm
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Anindya Roy wrote:look http://www.htmlgoodies.com/beyond/javascript/article.php/3470971/Java-vs-JavaScript.htm


Not a very good article.

I don't know when it was written (I can't find a publication date on it) but a number of ideas in the article are very out of date. For example, JavaScript is not only used inside HTML pages. It's also used in other environments. It talks about Java as if it's all about applets. Applets were popular in 1999, but nowadays almost nobody uses Java for programming applets.

Also:

Article wrote:In my opinion, JavaScript's main benefit is that it can be understood by the common human. It is much easier and more robust than Java.


"Much easier" and "more robust" (whatever that means) than Java? I don't think so.

The author of the article seems to be unaware that Java's popularity is mainly in server-side software, not in components that run inside browsers. The article has been written by someone who knows almost nothing about Java.
 
Marshal
Posts: 75851
361
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Let's get back to the original question and see if we can sort out that error.
I shall also move this discussion to our JavaScript forum.
 
Campbell Ritchie
Marshal
Posts: 75851
361
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which line was the error reported on?
 
Huang Xing
Greenhorn
Posts: 6
Mac Chrome Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for moving it to the JavaScript forums, campbell. And there was no line reported. It simply said "SyntaxError: Unexpected token ". I feel like maybe i have an extra space somewhere in there, as usually the Codecademy tells you what shouldn't be there (i.e., if i had an extra bracket, it would say "SyntaxError: Unexpected token {".
 
Sheriff
Posts: 67645
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Open the developer tools in the browser. All modern browsers have very powerful JavaScript debuggers and the console should give you much more information about the nature of the error.

Also when posting code, please UseCodeTags.
 
Bear Bibeault
Sheriff
Posts: 67645
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've gone ahead and added the code tags for you. See how much easier the code is to read?

Firstly, your formatting is inconsistent and makes reading the code a lot harder than it needs to be.

For example the following is a travesty:
Be sure to write such constructs as:
And finally, your last line is a syntax error. You use the function keyword when declaring the function, not when calling the function.
 
Bear Bibeault
Sheriff
Posts: 67645
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jesper de Jong wrote:Java and JavaScript are just as related as ham and hamster...



Obligatory comic:
 
Bear Bibeault
Sheriff
Posts: 67645
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But I guess an important question has remained unanswered: are you wanting to be learning Java or JavaScript?

If Java, you are barking up the wrong tree.

Though be aware that JavaScript is not a bad technology to have under your belt. Its importance and scope has skyrocketed over the past few years.

(And is one of the reasons that the previously linked article is so horribly wrong and bad.)
 
Huang Xing
Greenhorn
Posts: 6
Mac Chrome Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, as a prospective game designer, is Javascript fairly useless for me(at the time)? I just want to see how i am at coding, if I can do it without rage quitting over bugs every five minutes. I dont care if i can make really cool websites with javascript, i want to make games. I'll probably finish learning it eventually, even if it is unrelated to game design.

also: big shoutout to Bear Bibeault for fixing it
 
Bear Bibeault
Sheriff
Posts: 67645
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What kind of games? Modern JavaScript can be used for creating in-browser games. Not so sure about desktop games running in NodeJS or the Java JVM (the Java VM has a JavaScript interpreter), but it could be.

Console games? Then neither.

Mobile? If so, what platform?

So, we need some more information about your goal before being able to answer.
 
Huang Xing
Greenhorn
Posts: 6
Mac Chrome Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mobile, probably. iOS and android. Also in browser, later on.
 
Bear Bibeault
Sheriff
Posts: 67645
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For iOS you'll need to learn Swift (or Objective-C if old-school).

Android wil use Java* and the Android libraries.

In-browser, JavaScript is the right path.


* The code is Java, but converted to run on Dalvik.
 
Huang Xing
Greenhorn
Posts: 6
Mac Chrome Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Awesome. Thanks a lot for all the help
 
reply
    Bookmark Topic Watch Topic
  • New Topic