Hola,
I have applied every user story to the Random Quote Machine exercise as follows using REACT:
(App.js)
import React, {useEffect, useState} from 'react';
import './App.scss';
import COLORS_ARRAY from "./colorsArray"
let citasDB = "https://gist.githubusercontent.com/camperbot/5a022b72e96c4c9585c32bf6a75f62d9/raw/e3c6895ce42069f0ee7e991229064f167fe8ccdc/quotes.json"
const tlogo = "./580b57fcd9996e24bc43c53e.png"
function App() {
const [quote, setQuote] = useState("This is an ibru sentence: hkb fhuiog hgv goiug sd");
const [author, setAuthor] = useState("The Author");
const [randomNumber, setRandomNumber] = useState(0);
const [quotes, setQuotes] = useState(null);
const [accentColor, setAccentColor] = useState('#282c34')
const fetchQuotes = async (url) => {
const response = await fetch(url);
const parsedJSON = await response.json();
setQuotes(parsedJSON.quotes)
}
useEffect(() => {
fetchQuotes(citasDB)
}, [citasDB])
const generateRandomNumber = () => {
let randomInteger = Math.floor(quotes.length * Math.random())
setRandomNumber(randomInteger);
setAccentColor(COLORS_ARRAY[randomInteger])
setQuote(quotes[randomInteger].quote);
setAuthor(quotes[randomInteger].author);
}
return (
<div className="App">
<header className="App-header" style={
{backgroundColor: accentColor}
}>
<div id="quote-box" style={{color: accentColor}}>
<p id="text">
"{quote}"
</p>
<p id="author">
- {author}
</p>
<div id="buttons">
<button id="new-quote" style={
{backgroundColor: accentColor}
} onClick={() => generateRandomNumber()}>New quote</button>
<a id="tweet-quote" style={
{backgroundColor: accentColor}
} href={encodeURI('http://www.twitter.com/intent/tweet?text=${quote} -${author}')}>Tweet Quote</a>
</div>
</div>
</header>
</div>
);
}
export default App;
It runs ok on my laptop but they dont pass tests on codepen.
Can anybody tell me why?