- )
-}
\ No newline at end of file
+ const {defaultColor} = props;
+
+ const [color, setColor] = useState(defaultColor ? defaultColor : '');
+
+ return(
+
+
+
+
+
+ )
+}
diff --git a/16/1/src/container.js b/16/1/src/container.js
index 63a17f7..8162ace 100644
--- a/16/1/src/container.js
+++ b/16/1/src/container.js
@@ -10,8 +10,15 @@ export default function () {
function setPointsPlay(check){
+ // ternary is better used inside:
+ // const newValue = points + (check ? 10 : -5)
+ // (to save duplication)
const newValue = check ? points+10 : points-5;
+ // I thought you liked ternaries...
+ // setPoints(newValue > 0 ? newValue : 0)
+ // but my favorite is:
+ // setPoints(Math.min(newValue, 0))
if(newValue > 0) setPoints(newValue);
else setPoints(0);
@@ -35,4 +42,4 @@ export default function () {
function getRndInteger(min, max) {
return Math.floor(Math.random() * (max - min) ) + min;
-}
\ No newline at end of file
+}
diff --git a/16/1/src/play.js b/16/1/src/play.js
index bdbada3..c48d18f 100644
--- a/16/1/src/play.js
+++ b/16/1/src/play.js
@@ -7,11 +7,33 @@ export default function play(props) {
const {setPointsPlay, placeRed} = props;
+ // You're hiding a lot of logic inside the map,
+ // and that makes the code hard to read
+ // Better to refactor and extract most of the code to a sub-component
+ // or to a helper function
+
return(
{Array(10).fill(null).map( (item, index) => (
-
setPointsPlay(index+1 === placeRed) }>
+
setPointsPlay(index+1 === placeRed) }>
+
))}
)
-}
\ No newline at end of file
+
+ // What I would write:
+ return(
+