mirror of
https://github.com/10h30/fullstackopen.git
synced 2026-07-20 06:53:26 +09:00
Completed 1.12 (anecdotes step1)
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import React, { useState } from 'react'
|
||||
|
||||
const App = () => {
|
||||
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 90 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'
|
||||
]
|
||||
|
||||
const [selected, setSelected] = useState(0)
|
||||
const setRandom = () => {
|
||||
const min = 0
|
||||
const max = anecdotes.length-1
|
||||
const random = Math.floor(Math.random() * (max-min+1)) + min
|
||||
console.log(random)
|
||||
setSelected(random)
|
||||
}
|
||||
return (
|
||||
<div>
|
||||
<p>{anecdotes[selected]}</p>
|
||||
<button onClick={setRandom}>Next Anecdote</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default App
|
||||
@@ -0,0 +1,13 @@
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
|
||||
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
|
||||
sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
|
||||
monospace;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import ReactDOM from 'react-dom'
|
||||
import App from './App'
|
||||
|
||||
ReactDOM.render(
|
||||
<App />,
|
||||
document.getElementById('root')
|
||||
)
|
||||
Reference in New Issue
Block a user