From 6a6aaf56723a8e6b5c1778e564c35fc0ea200385 Mon Sep 17 00:00:00 2001
From: Moon <108756201+LifeAdventurer@users.noreply.github.com>
Date: Tue, 3 Oct 2023 20:57:50 +0800
Subject: [PATCH] Update quote.js replace listing quotes by fetching a json
file
---
quote.js | 39 ++++++++++++---------------------------
1 file changed, 12 insertions(+), 27 deletions(-)
diff --git a/quote.js b/quote.js
index 3b6064d..cbc07bf 100644
--- a/quote.js
+++ b/quote.js
@@ -2,38 +2,23 @@ const quoteElement = document.getElementById("quote");
const authorElement = document.getElementById("author");
const buttonElement = document.querySelector("button");
-const quotes = [
- {
- quote: "To AC is human. To AK divine.",
- author: "Moon"
- },
- {
- quote: "Life is like riding a bicycle. To keep your balance, you must keep moving.",
- author: "Albert Einstein"
- },
- {
- quote: "A dream is what makes people love life even when it is painful.",
- author: "Theodore Zeldin"
- },
- {
- quote: "Don’t quit. Suffer now and live the rest of your life as a champion.",
- author: "Muhammad Ali"
- },
-];
+let quotes = [];
+
+fetch("quotes.json")
+.then(response => response.json())
+.then(data => {
+ quotes = data.quotes;
+});
+
function Appear() {
+ console.log(quotes);
const index = Math.floor(Math.random() * quotes.length);
- const { quote, author } = quotes[index];
- console.log(index)
- quoteElement.innerHTML = `"` + quote + `"` ;
+ const {quote, author} = quotes[index];
+ quoteElement.innerHTML = `"` + quote + `"` ;
authorElement.innerHTML = "- " + author;
}
function getQuote() {
- let a = parseInt(Math.random() * 255);
- let str = `rgba(${a}, ${Math.abs(a - 127)}, ${Math.abs(a - 255)}, 0.55)`;
- console.log(str);
- Update(str);
+ Update();
}
-
-getQuote();
\ No newline at end of file