Этот код перемещается по трем массивам в случайном порядке всякий раз, когда нажимает div. Я хотел бы, чтобы два массива «кавычки» и «авторы» отображали один и тот же порядок случайных массивов. Я хотел бы, чтобы «Третий» равнялся «-Терней» и «Сначала» равным «-Первым» или кавычками [x] == authors [x], когда x является случайным.Выберите случайные предметы из двух массивов и сопоставьте порядок предметов
Также есть простой способ комбинировать функцию .ready и .click, чтобы я не поставил точно такой же код в обоих случаях?
var colors = ["#3b609b", "#9b3b3b", "#3b9b81", "#7da5a4"];
var quotes = ["First", "Second", "Third", "Fourth"];
var authors = ["-First", "-Second", "-Third", "-Fourth"];
$(document).ready(function() {
//Variables to shuffle through "colors", "quotes" and "authors" arrays.
var rand = Math.floor(Math.random() * colors.length);
var rand2 = Math.floor(Math.random() * quotes.length);
var rand3 = Math.floor(Math.random() * authors.length);
//Display quotes/authors and change background colors.
$("body, .button, .social").css("background-color", colors[rand]);
$(".quote").html(quotes[rand2]).css("color", colors[rand]);
$(".author").html(authors[rand3]).css("color", colors[rand]);
$(".button").click(function() {
//Variables to shuffle through "colors", "quotes" and "authors" arrays.
var rand = Math.floor(Math.random() * colors.length);
var rand2 = Math.floor(Math.random() * quotes.length);
var rand3 = Math.floor(Math.random() * authors.length);
//Display quotes/authors and change background colors when div is clicked.
$("body, .button, .social").css("background-color", colors[rand]);
$(".quote").html(quotes[rand2]).css("color", colors[rand]);
$(".author").html(authors[rand3]).css("color", colors[rand]);
});
});
Большое спасибо! Теперь он отлично работает! – Zach