syntax error codepen full view

i'm trying to complete the wikipedia search for freecodecamp,(in codepen), and i'm running into this problem where my code will run in codepen's edit view and debug view, but fails to run in, "details view",and "full view". The error given in the console in details, and full view, is,

"Uncaught SyntaxError: missing ) after argument list"

, yet jshint can't seem to find the error, and the code seems to run fine otherwise? Is it simply a codepen bug?

Here is my pen. Very sketchy. :o

https://codepen.io/ohrha/pen/wgZYvM?editors=1000 (editor view)(working) https://codepen.io/ohrha/full/wgZYvM/ (full view)(not working)

    $.ajax ({
              type:'GET',
              url: prefixSearch,
              dataType:'jsonp',
              success: function(jason){
                     var prefixSearchResults= jason;
                     console.log(prefixSearchResults.query.prefixsearch.length);
                     console.log(prefixSearchResults.query.prefixsearch[0].pageid);
                     console.log(prefixSearchResults.query.prefixsearch[0].title);


                     for(var i= 0; i<prefixSearchResults.query.prefixsearch.length;i++){
                     curid.push( "https://crossorigin.me/https://en.wikipedia.org/w/api.php?action=query&format=json&prop=extracts&exchars=175&explaintext&pageids="+prefixSearchResults.query.prefixsearch[i].pageid);  queryResultsArray.push(prefixSearchResults.query.prefixsearch[i].pageid);
               queryResultUrls.push("<a rel="nofollow" rel="noreferrer"href= 'https://en.wikipedia.org/?curid="+prefixSearchResults.query.prefixsearch[i].pageid+">"+prefixSearchResults.query.prefixsearch[i].title+"</a><br>"+prefixSearchResults); 

//here the "Uncaught SyntaxError: missing ) after argument list" error occurs.
                       extracts.push(prefixSearchResults.query.prefixsearch[i].pageid);
                       console.log(extracts);
                     }
                     }}); 

Any ideas?

Answers 1

  • An alternative to escaping the quotes like @subwaymatch pointed out, you could just use single quotes here

    queryResultHrefLink='<a href="https://en.wikipedia.org/?curid='+prefixSearchResults.query.prefixsearch[i].pageid+'">'+prefixSearchResults.query.prefixsearch[i].title+'</a><br>'+prefixSearchResults;
    

Related Articles