Skip to content
Advertisement

Uncaught SyntaxError: unexpected token: string literal in javascript. I can’t figure out what’s wrong [closed]

This is my code, a simple sequel of function were I generate two number, one for the user, one for the PC and who scores the highest number win the game. Firefox has come out with Uncaught SyntaxError: unexpected token: string literal error, I checked my code and everything seems ok to me, I can’t figure out what’s wrong and generates that error

JavaScript

Advertisement

Answer

  1. You are missing a plus + sign while adding the strings with variables.


    What you are doing:

    JavaScript

    What it should be:

    JavaScript



  1. When you are using the same type of quote in a string then you have two ways to correct it:


    • Use different strings, like:

      JavaScript

    • Or you can escape that string using , Like

      JavaScript



Try this:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement