Solved

JavaScript Error: Unexpected Token

Posted on 2016-09-24
2
46 Views
Last Modified: 2016-09-25
I am  working on a exercise(End of Chapter 2) in the "Eloquent JavaScript" book.

I am trying to build a chessboard but I am getting an error, "Unexpected Token".

http://codepen.io/isogunro/pen/dpvKJp?editors=1012

Any help would be appreciated.

Thanks!
0
Comment
Question by:Isaac
2 Comments
 
LVL 10

Assisted Solution

by:Jeffrey Dake
Jeffrey Dake earned 300 total points
ID: 41814259
On the third line you don't have x set to anything.   Unexpected token is JavaScripts way of telling you that you have incorrect syntax.
0
 
LVL 21

Accepted Solution

by:
Kim Walker earned 200 total points
ID: 41814280
Jeffrey Dake is correct about the error on line 3.

More specifically, unexpected token simply means that a token appeared where something else was expected. A token in javascript is a punctuation character or operator. There are several tokens in the third line of your javascript -- the parentheses, the equals operator, the semi-colons, the less-than-or-equal-to operator (<=), the positive increment operator (++), and the left curly brace. In this case, the parser was expecting a value for the equals operator but instead encountered the semi-colon statement terminator. So the semi-colon token was unexpected.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now