このコードは、divがクリックされるたびに3つの配列をランダムに並べ替えます。 2つの配列 "引用符"と "著者"に同じランダム配列を表示させる必要があります。私はxがランダムであるときに "第3"が "第3"と "第1"が " - 最初"または引用[x] ==著者[x]と等しいことを望みます。2つの配列からランダムな項目を選択し、項目の順序に一致させます
また、.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