我正在通過Free Code Camp's "Random Quote Machine"工作,並且我構建了一個非常(強調非常)基本模型,但是我無法弄清楚如何引用它們並用我的代碼來推送它們。我是否必須更改當前的Javascript代碼來發送推文,還是有辦法用我目前沒有意識到的代碼發送推文?我知道有一個解決方案another question like this,但我不明白。非常感謝。隨機引用機器,鳴叫報價
var quotes= [
'I love you the more in that I believe you had liked me for my own sake
and for nothing else. John Keats',
'But man is not made for defeat. A man can be destroyed but
not defeated. Ernest Hemingway',
'When you reach the end of your rope, tie a knot in it and
hang on. Franklin D. Roosevelt',
'Always do what is right. It will gratify half of mankind
and astound the other. ― Mark Twain',
'Whenever you find yourself on the side of the majority, it
is time to pause and reflect. Mark Twain',
'It is curious that physical courage should be so common in
the world, and moral courage so rare.- Mark Twain in Eruption',
'A man should not be without morals; it is better to have
bad morals than none at all.- Mark Twain\'s Notebook',
'The most permanent lessons in morals are those which come,
not of book teaching, but of experience.- A Tramp Abroad',
'But the fact that he can do wrong proves his moral
inferiority to any creatures that cannot.― Mark Twain',
'\「Wrong does not cease to be wrong because the majority
share in it.\」 ― Leo Tolstoy',
'\「Right is right even if no one is doing it; wrong is wrong
even if everyone is doing it.\」 ― Augustine of Hippo'
]
function nextQuote() {
var randomNumber = Math.floor(Math.random()*quotes.length);
document.getElementById("displayQuote").innerHTML = quotes[randomNumber];
}
<h1>Random Quote Machine</h1>
<!--Javascript will go in div-->
<div>
<h2 id="displayQuote"></h2>
</div>
<button onclick="nextQuote()">New Quote</button>
<button id="tweetQuote"><a>Tweet</a></button>
我做了它,所以它並沒有換行,你是對是顯著更快。你知道如何從那裏發佈報價嗎?我訪問過這個帖子(https://stackoverflow.com/questions/45172377/twitter-share-button-with-random-quote?rq=1),但我不明白他們在做什麼,通過添加addEventListener。 (我訪問過W3schools)我知道這是一個初學者的問題,感謝您的耐心等待 –
@JohnSmith請注意:我的代碼中存在一個錯誤。現在它的更新和好... – Axel
不幸的是,我還沒有15個代表,「它被記錄,但沒有公開添加。」當我得到15時,我一定會回來並重新按下投票按鈕。你的善舉不會被忽視。感謝您的幫助。 –