Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMIA ASHCROFT
2,442 PointsUncaught SyntaxError: missing ) after argument list
My code isn't running. In console the error is: LINE 5 Uncaught SyntaxError: missing ) after argument list - but there are no missing ).
var answer = prompt('WHat language is the name of a gem?'); if ( answer === 'Ruby' ) { document.write("<p>That's right!</p>") } else { document.write('<p>Sorry that's wrong</p>') }
Help!
4 Answers
Camilo Lucero
27,692 PointsCheck this line:
'<p>Sorry that's wrong < /p>'
This line is wrapped in single quotation marks, but the word that's also has a single quotation mark. Therefore, the program thinks that you mean '<p>Sorry that' and expects a parenthesis immediately after.
This can be fixed in a couple of ways:
1 - Wrap the line in double quotes instead of single quotes.
"<p>Sorry that's wrong < /p>"
2 - Add a bachslash ( \ ) before the single quote of that's . This is called escaping and will make the single quote be read as part of the string instead of the end of it.
'<p>Sorry that\'s wrong < /p>'
Jennifer Nordell
Treehouse TeacherHi there, MIA ASHCROFT ! First, you're doing terrific. I know that from your perspective, it looks like all the parentheses are there. But from JavaScript's perspective, they aren't. The problem is with the string in the document.write()
in the else
part of the statement. You began the string with a single quotation mark, so when it gets to the apostrophe (which is the same) it thinks that is the end of the string and is, of course, expecting a closing parenthesis immediately after. Take a look.
You wrote:
document.write('<p>Sorry that's wrong</p>')
Note the strange coloring of s wrong</p>')
. That's because it thinks the string ended after "that". Now there are a couple of solutions here. You could enclose the whole thing in double quotes instead of single:
document.write("<p>Sorry that's wrong</p>")
Or alternatively, you could "escape" the apostrophe:
document.write('<p>Sorry that\'s wrong</p>')
Hope this helps!
Cheo R
37,150 PointsJavaScript uses the \ (backslash) as an escape characters for:
\' single quote
\" double quote
\ backslash
\n new line
\r carriage return
\t tab
\b backspace
\f form feed
\v vertical tab (IE < 9 treats '\v' as 'v' instead of a vertical tab ('\x0B'). If cross-browser compatibility is a concern, use \x0B instead of \v.)
\0 null character (U+0000 NULL) (only if the next character is not a decimal digit; else itβs an octal escape sequence) Note that the \v and \0 escapes are not allowed in JSON strings.
So you need to escape the apostrophes in That's Right! and Sorry that's wrong.
Christian Bartram
1,193 PointsIf you are using es6 you can also use the backtick (`) character's to avoid issues like this altogether! For instance :
document.write(`<p>Sorry that's wrong</p>`);