scrimba
Frontend Career Path
React basics
Notes & Tenzies
Tenzies: Roll dice button
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

AboutCommentsNotes
Tenzies: Roll dice button
Expand for more info
App.js
run
preview
console
import React from "react"
import Die from "./Die"


export default function App() {
/**
* Challenge: Create a `Roll Dice` button that will re-roll
* all 10 dice
*
* Clicking the button should generate a new array of numbers
* and set the `dice` state to that new array (thus re-rendering
* the array to the page)
*/

const [dice, setDice] = React.useState(allNewDice())

function allNewDice() {
const newDice = []
for (let i = 0; i < 10; i++) {
newDice.push(Math.ceil(Math.random() * 6))
}
return newDice
}

const diceElements = dice.map(die => <Die value={die} />)

return (
<main>
<div className="dice-container">
{diceElements}
</div>
{/*New button here*/}
</main>
)
}
Console
!
"Warning: Each child in a list should have a unique "key" prop. Check the render method of `App`. See https://fb.me/react-warning-keys for more information. in Die (created by App) in App"
,
/index.html
-4:41