From 48736417d654475b93cff4db6efc019195850180 Mon Sep 17 00:00:00 2001 From: Anish Lakhwara Date: Mon, 15 May 2023 22:05:49 +1000 Subject: [PATCH] exercise 1.12 --- part1/src/App.js | 70 +++++++++++++----------------------------------- 1 file changed, 18 insertions(+), 52 deletions(-) diff --git a/part1/src/App.js b/part1/src/App.js index 27d1a03..16be05a 100644 --- a/part1/src/App.js +++ b/part1/src/App.js @@ -1,70 +1,36 @@ import { useState } from 'react' -const StatisticLine = ({ value, text }) => { - // Whoops, I already made it a table - return ( - - {text} - {value} - - ) -} - -const Stats = ({ positive, neutral, negative, total, votes }) => { - if (votes === 0) { - return ( - <> -

No Votes Cast Yet

- - ) - } +const Button = ({ handler, text }) => { return ( <> -

Results

- - - - - - + ) } -const Button = ({ handler, text }) => { - return ( - - ) -} - const App = () => { - const [good, setGood] = useState(0) - const [neutral, setNeutral] = useState(0) - const [bad, setBad] = useState(0) - const total = good - bad - const votes = good + neutral + bad + const anecdotes = [ + 'If it hurts, do it more often.', + 'Adding manpower to a late software project makes it later!', + 'The first 90 percent of the code accounts for the first 10 percent of the development time...The remaining 10 percent of the code accounts for the other 90 percent of the development time.', + 'Any fool can write code that a computer can understand. Good programmers write code that humans can understand.', + 'Premature optimization is the root of all evil.', + 'Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.', + 'Programming without an extremely heavy use of console.log is same as if a doctor would refuse to use x-rays or blood tests when diagnosing patients.', + 'The only way to go fast, is to go well.' + ] - const incPositive = () => { - setGood(good + 1) - } + const [selected, setSelected] = useState(0) - const incNegative = () => { - setBad(bad + 1) - } - - const incNeutral = () => { - setNeutral(neutral + 1) + const randomText = () => { + const value = Math.floor(Math.random() * anecdotes.length) + setSelected(value) } return (
-

Feedback

-
) }