Last active
February 29, 2024 16:57
-
-
Save lejonmanen/f46f43bfb13181222825fc0afcd9cdfc to your computer and use it in GitHub Desktop.
Conditional rendering exercise
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
The Budget component uses "conditional rendering" to do | |
different things based on its props. What will each line | |
in the App component render? | |
*/ | |
const App = () => ( | |
<main> | |
<Budget value={5500} /> | |
<Budget value={240} /> | |
<Budget value={0} /> | |
<Budget value={-150} /> | |
<Budget value={120} /> | |
</main> | |
) | |
// Assume that there are CSS classes named "low" and "high" defined in App.css. | |
const Budget = (props) => { | |
let css = '', display = props.value | |
if( props.value < 0 ) { | |
css = 'low' | |
} | |
else if( props.value >= 1000 ) { | |
css = 'high' | |
} | |
else if( props.value === 0 ) { | |
display = 'Empty!' | |
} | |
return ( | |
<span className={css}> {display} </span> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment