Javascript is not working

Hi,
I’m using the 2016 version of the book (seems like that), just in case.

Now I’m in 7th chapter, but I have been getting a javascript error such as “Uncaught SyntaxError: Invalid or unexpected token”, since the chapter 6 or sth when javascript firstly came out. Actually there were more error msgs like “failed to load resource: the server responded with a status of 404 (not found)” and all.

I had an issue that the original link given by the book was not working (so I was using the random images) then found this forum, there was a new link so I fixed that one.
I’m sort of ignoring why js is not working in the page, as I can’t find a bug right now (I mean I’m keep checking it, but I literally can’t find it) and google nor any other websites didn’t answer. So, i assume it must be caused by very general mistake or sth… still don’t know why it is not working at all.

Did anyone have similar issue or even get an answer for this?

A little trivia : I’m also keep having an eye on freecodecamp.org and other websites as well to see the concepts of the elements and all.

Hi,

The error you are seeing should also show a line number in the console.

In this case the syntax error is on line 2 of main.js.

The line displayed is where the browser first encountered code it could not parse so sometimes the error is actually a few lines before the line it reports.

Once, you find the line of the error. If you cannot find the syntax error, feel free to share your code, and I can help you find it.

Alternatively, in the resources file. There is a folder called book-solutions. You will find the solution to each chapter there so you can use that javascript file to compare with your own.

1 Like

Hi, Loren.

Thanks for explanation!
I checked that mine is main.js:4, and line number 4 is where the first line of my script starts.
Then I was comparing my code with the one in solutions file, also cross-checking with console.
There was an error like, really minor but critical(well maybe that’s what coding is)
like

let DETAIL_IMAGE_SELECTOR = '[data-image-role="target"]';
let DETAIL_TITLE_SELECTOR = '[data-image-role="title"]';

it is revised now, but before I had one or more single quote there.

Yet also,

function setDetailsFromThumb(thumbnail) {
  'use strict';
  setDetails(imageFromThumb(thumbnail), titleFromThumb(thumbnail));
}

the second (thumbnail) had one more ) - I don’t know its name -.
Above is revised version (it is working) if anyone else who’s lost as me is checking this page.

Thanks a lot to your mentioning about checking the line number in console and all!
Wish you a nice day!

1 Like

This worked for me. You can also try it.