Can't get "unknown" author on a twitter share screen?

Can't get "unknown" author on a twitter share screen?
0.0 0

#1

Hi guys, I’m almost done with my random quote machine but there is a one small issue that I encountered. When u press “get quote” button for the unknown author and press share via twitter, it will not display unknown author of a particular quote. Other quotes with a specific author are displayed fine. Also how can you separate quote text from the author via JavaScript. Because I want author to be on the text line.

Here is my codepen link: http://codepen.io/Vladimirpak/pen/WRLzGe

Thanks!


#2
// result of data search
var quote = "If you come to a fork in the road, take it.";
var author = ""; // You need to add a value here if you are displaying it later

// easy fix
if (!author) author = "- Unknown"

// then it is easy to do the following
$('.author-text').text('said by ' + author);
window.open(... + author + ...));

// bonus tip, use ES6 template strings not the long crap you were doing
// also, \n does nothing on twitter, so you can't really separate it that way
window.open(`https://twitter.com/intent/tweet?text="${quote}" -- ${author}`);

#3

Thank You very much. I only need this fix : if (!author) author = “- Unknown”;
and it solved problem :slight_smile: