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 trial

JavaScript

Mahmoud Talass
Mahmoud Talass
9,274 Points

Idk whats wrong with my code

I keep getting "app.js:4 Uncaught SyntaxError: missing ) after argument list" in the console and idk what exactly I did wrong, there doesn't seem to be a missing parenthesis in my code. can someone please tell me what to do?

const $odd = $('a:odd');
const $secureLinks = $('a[href^="https://"]');
const $pdfs = $('a[href$=".pdf"]');
const $pdfCheckbox = $('<label><input type='checkbox'> Allow PDF downloads</label>');

$secureLinks.attr('target', '_blank');
$pdfs.attr('download', true);

$odd.css('backgroundColor', 'lightgrey');
$secureLinks.addClass('secure');

$pdfs.addClass('pdf');

$pdfs.on('click', function(event){
  if ($(':checked').length === 0) {
    event.preventDefault();
    alert('Please check the box to allow PDF downloads.');
  } 
});

$('#links').append($pdfCheckbox);

$('a').each(function(index, link){
  const url = $(link).attr('href');
  $(link).parent().append(`(${url})`);
});
<!DOCTYPE html>
<html>
<head>
    <title>jQuery Weekly</title>
    <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" title="no title" charset="utf-8">
</head>
<body>
<div class="box">
    <h1>jQuery Weekly</h1>
    <div id="links">
        <ul>
            <li><a href='https://learn.jquery.com/'>Learn jQuery</a></li>
            <li><a href='http://treehouse-project-downloads.s3.amazonaws.com/jquery-basics/jquery_cheatsheet.pdf'>jQuery Cheatsheet</a></li>
            <li><a href='https://api.jquery.com/'>jQuery Documentation</a></li>
            <li><a href='https://developer.mozilla.org/en-US/docs/Glossary/jQuery'>jQuery Glossary</a></li>
        </ul>

    </div>
</div>
    <script src="js/jquery-3.2.1.min.js"></script>
    <script src="js/app.js"></script>
</body>
</html>

1 Answer

Hi Mahmoud,

on line 4 when you define the input type you are using single quotation marks...

This does not work because you defined the whole string with single quotation marks, so any ' will be regarded as the end of the string.

There are a couple of ways you can avoid this issue:

1) You use double colons for the string -> then you can use single quotations inside the string. (or alternatively the other way around: single quotations for the string and double inside of it)

2) You use the so-called "escape character" \ before the quotation mark -> any letter or symbol after the escape character will be taken literal regardless of what it would usually mean.

3) You use so-called template literals `` which allow you to use single as well as double quotes inside of it. To learn more about template literals have a look here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

Have not checked if there were other issues in your code but that's the one on line 4.

Blessings from Berlin and happy java-scripting, Nils

PS: If my answer helped you or solved your issues, please upvote my answer and/or mark it as "Best answer" (so people browsing the community forum know your issue is solved)