Вот вам рабочий код. У вас много syntax error
s и много typos
.
Вы неправильно пишете содержимое arrays
(кавычки) и (страна), поэтому ваш код не работал. Также вам не нужно закрывать функции с помощью ;
, это не обязательно.
Подробнее о JS массивах можно узнать здесь
Обе кнопки работают и отображение результатов с помощью Math.Random
Запустите фрагмент ниже, чтобы убедиться, что он работает.
var quotes = [
`Associate yourself with men of good quality if you esteem your own reputation for tis
better to be alone than in bad company. - George Washington`,
`To be good, and to do good, is all we have to do. -John Adams`,
`Nothing can stop the man with the right mental attitude from achieving his goal; nothing on
earth can help the man with the wrong mental attitude. -Thomas Jefferson`,
`If your actions inspire others to dream more, learn more, do more and become more, you are
a leader - John Quincy Adams`,
`Any man worth his salt will stick up for what he believes right, but it takes a slightly
better man to acknowledge instantly and without reservation that he is in error. -Andrew
Jackson`,
`While men inhabiting different parts of this vast continent cannot be expected to hold the
same opinions, they can unite in a common objective and sustain common principles. -Franklin
Pierce`,
`In the time of darkest defeat, victory may be nearest. -William Mckinley`,
`Theres good in everybody. Boost. Dont knock -Warren G. Harding`,
`Pessimism never won any battle. -Dwight D. Eisenhower`,
`Without passion you dont have energy, without energy you have nothing. -Donald J. Trump`
]
var countries = [
'Amennia' + '<a href = "https://en.wikipedia.org/wiki/Armenia">Wiki</a>',
'Swaziland',
'Canada'
]
function newQuote() {
var randomNumber = Math.floor(Math.random() * (quotes.length));
document.getElementById('quoteDisplay').innerHTML = quotes[randomNumber];
}
function newCountry() {
var randomNumber2 = Math.floor(Math.random() * (countries.length));
document.getElementById('countryDisplay').innerHTML = countries[randomNumber2];
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>quote gen</title>
</head>
<body>
<h1>simple quote generator</h1>
<div id="quoteDisplay">
</div>
<button onclick="newQuote()"> New Quote</button>
<div id="countryDisplay">
</div>
<button onclick="newCountry()"> New Country</button>
</body>
</html>