- This is a primary alert-check it out!
+
+ This is a primary alert - check it out!
);
};
+
Alert.propTypes = {
- color: PropTypes.string,
- text: PropTypes.string
+
};
-// here is where the alert component is being used, you don't have to edit this part,
-// but it helps you understand what properties are being passed to the component
+// Here is where the
component is being used, you don't have to edit this part
+// But it helps you understand what properties are being passed to the component
ReactDOM.render(
,
document.querySelector("#myDiv")
);
diff --git a/exercises/04-conditional-rendering/solution.hide.jsx b/exercises/04-conditional-rendering/solution.hide.jsx
index 58b6d171..e9e8b193 100644
--- a/exercises/04-conditional-rendering/solution.hide.jsx
+++ b/exercises/04-conditional-rendering/solution.hide.jsx
@@ -2,36 +2,30 @@ import React from "react";
import ReactDOM from "react-dom";
import PropTypes from "prop-types";
-const Alert = props => {
- //add the condition inside this function
-
- if (props.show === false) {
- return null;
- }
- else {
- // return here the component html
- return (
-
- This is a primary alert-check it out!
-
- );
-
- }
-
-
-
+const Alert = (props) => {
+ // Add the condition inside this function
+ if (props.show === false) {
+ return null;
+ } else {
+ return (
+
+ {props.text}
+
+ );
+ }
};
+
Alert.propTypes = {
- color: PropTypes.string,
- text: PropTypes.string
+ show: PropTypes.bool,
+ text: PropTypes.string,
};
-// here is where the alert component is being used, you don't have to edit this part,
-// but it helps you understand what properties are being passed to the component
+// Here is where the
component is being used, you don't have to edit this part
+// But it helps you understand what properties are being passed to the component
ReactDOM.render(
-
,
- document.querySelector("#myDiv")
+
,
+ document.querySelector("#myDiv")
);
diff --git a/exercises/04-conditional-rendering/tests.js b/exercises/04-conditional-rendering/tests.js
index 65f1d16e..eddcf3d3 100644
--- a/exercises/04-conditional-rendering/tests.js
+++ b/exercises/04-conditional-rendering/tests.js
@@ -10,24 +10,23 @@ jest.mock("react-dom", () => ({ render: jest.fn() }));
test("ReactDOM needs to be called once", () => {
expect(ReactDOM.render.mock.calls.length).toBe(1);
});
-test('Use "if/else" conditional', function(){
+
+test('Use an "if...else" conditional', function(){
const data = fs.readFileSync('./exercises/04-conditional-rendering/app.jsx');
const regex = /\s*if\s*/gm;
expect(regex.exec(data)).toBeTruthy();
});
-
-
test("The component Alert should return the exact HTML", () => {
const tree = renderer.create(ReactDOM.render.mock.calls[0][0]).toJSON();
expect(tree).toMatchInlineSnapshot(`
- This is a primary alert-check it out!
+ This is a primary alert - check it out!
`);
diff --git a/exercises/04.1-conditional-rendering/README.es.md b/exercises/04.1-conditional-rendering/README.es.md
index 34a3df7b..94fe06e6 100644
--- a/exercises/04.1-conditional-rendering/README.es.md
+++ b/exercises/04.1-conditional-rendering/README.es.md
@@ -1,21 +1,19 @@
# `04.1` Conditional Rendering
-Hagamos nuestro componente `
` un poco más inteligente.
+Hagamos nuestro componente `` un poco más inteligente.
Cuando usas JSX tienes todas las funcionalidades de JavaScript disponibles: Variables, Bucles, Condicionales, etc.
-Ya hemos usado bucles y variables, ¡es momento de usar condicionales!
-
-Por ejemplo, el siguiente código renderiza una alerta roja o naranja dependiendo de la propiedad `color`.
+Por ejemplo, el siguiente código renderiza una alerta roja o amarilla dependiendo de la propiedad `color`.
```jsx
const colorClasses = {
'red': 'alert-danger',
- 'orange': 'alert-warning'
+ 'yellow': 'alert-warning'
}
- This is a primary alert-check it out!
+ This is an alert - check it out!
```
@@ -23,24 +21,24 @@ Estamos declarando una variable `colorClasses` que contendrá todos los class na
## 📝 Instrucciones:
-1. Crea un componente `` que renderice una [bootstrap alert](https://getbootstrap.com/docs/4.0/components/alerts/#examples).
+1. Crea un componente `` que cambie de color cuando se modifique la propiedad `color` siguiendo los [colores de las alertas de bootstrap](https://getbootstrap.com/docs/5.0/components/alerts/#examples).
## 💡 Pista:
El componente debe ser capaz de recibir las siguientes dos propiedades:
-+ Text (string): El texto mostrado en la alerta.
++ `text` (string): El texto mostrado en la alerta.
-+ Color (string): Rojo o naranja.
++ `color` (string): El color red o yellow.
```jsx
-//para el color rojo
+{/* Para el color rojo */}
- This is a primary alert—check it out!
+ This is a danger alert - check it out!
-//para el color amarillo
+{/* Para el color amarillo */}
- This is a primary alert—check it out!
+ This is a warning alert - check it out!
-```
\ No newline at end of file
+```
diff --git a/exercises/04.1-conditional-rendering/README.md b/exercises/04.1-conditional-rendering/README.md
index 0b3882c2..210964c6 100644
--- a/exercises/04.1-conditional-rendering/README.md
+++ b/exercises/04.1-conditional-rendering/README.md
@@ -4,22 +4,20 @@ tutorial: "https://www.youtube.com/watch?v=hEY3YRQN0uk"
# `04.1` Conditional Rendering
-Let's make our `` component a little bit smarter.
+Let's make our `` component a little bit smarter.
-When using JSX you have all of the Javascript functionalities available: Variables, Loops, Conditionals, etc.
+When using JSX, you have all the JavaScript functionalities available: Variables, Loops, Conditionals, etc.
-We have already used loops and variables, it's time to use conditionals!
-
-For example, the following code renders a red or orange alert depending on the `color` property.
+For example, the following code renders a red or yellow alert, depending on the `color` property.
```jsx
const colorClasses = {
'red': 'alert-danger',
- 'orange': 'alert-warning'
+ 'yellow': 'alert-warning'
}
- This is a primary alert-check it out!
+ This is an alert - check it out!
```
@@ -27,24 +25,24 @@ We are declaring a variable `colorClasses` that will contain all the class names
## 📝 Instructions:
-1. Create an `` component that renders a [bootstrap alert](https://getbootstrap.com/docs/4.0/components/alerts/#examples).
+1. Create an `` component that changes its color by modifying the `color` property following [bootstrap's alert color names](https://getbootstrap.com/docs/5.0/components/alerts/#examples).
## 💡 Hint:
The component must be able to receive the following 2 properties:
-+ Text (string): The text content that will be displayed on the alert.
++ `text` (string): The text content that will be displayed on the alert.
-+ Color (string): Red or Orange.
++ `color` (string): The colors red or yellow.
```jsx
-//for red color
+{/* For red color */}
- This is a primary alert—check it out!
+ This is a danger alert - check it out!
-//for yellow color
+{/* For yellow color */}
- This is a primary alert—check it out!
+ This is a warning alert - check it out!
-```
\ No newline at end of file
+```
diff --git a/exercises/04.1-conditional-rendering/app.jsx b/exercises/04.1-conditional-rendering/app.jsx
index fd822fbc..a577e39f 100644
--- a/exercises/04.1-conditional-rendering/app.jsx
+++ b/exercises/04.1-conditional-rendering/app.jsx
@@ -3,7 +3,7 @@ import ReactDOM from "react-dom";
import PropTypes from "prop-types";
const Alert = props => {
- //your component here
+ // Your component here
};
Alert.propTypes = {
@@ -11,12 +11,12 @@ Alert.propTypes = {
text: PropTypes.string
};
-// here is where the alert component is being used, you don't have to edit this part,
-// but it helps you understand what properties are being passed to the component
+// Here is where the component is being used, you don't have to edit this part
+// But it helps you understand what properties are being passed to the component
ReactDOM.render(
,
document.querySelector("#myDiv")
);
diff --git a/exercises/04.1-conditional-rendering/solution.hide.jsx b/exercises/04.1-conditional-rendering/solution.hide.jsx
new file mode 100644
index 00000000..2e2512c8
--- /dev/null
+++ b/exercises/04.1-conditional-rendering/solution.hide.jsx
@@ -0,0 +1,32 @@
+import React from "react";
+import ReactDOM from "react-dom";
+import PropTypes from "prop-types";
+
+const Alert = (props) => {
+ // Your component here
+ const colorClasses = {
+ red: "alert-danger",
+ yellow: "alert-warning",
+ };
+
+ return (
+
+ {props.text}
+
+ );
+};
+
+Alert.propTypes = {
+ color: PropTypes.string,
+ text: PropTypes.string,
+};
+
+// Here is where the component is being used, you don't have to edit this part
+// But it helps you understand what properties are being passed to the component
+ReactDOM.render(
+ ,
+ document.querySelector("#myDiv")
+);
diff --git a/exercises/04.1-conditional-rendering/tests.js b/exercises/04.1-conditional-rendering/tests.js
index 2d1de630..3a6fb353 100644
--- a/exercises/04.1-conditional-rendering/tests.js
+++ b/exercises/04.1-conditional-rendering/tests.js
@@ -17,7 +17,7 @@ test("The component Alert should return the exact HTML", () => {
className="alert alert-danger"
role="alert"
>
- OMG! Something really bad has happended!
+ OMG! Something really bad has happened!
` puede renderizar en **orange** (naranjo) o **red** (rojo) dependiendo del valor de su propiedad `color`.
+Justo ahora este componente `
` puede renderizar en **yellow** o **red** dependiendo del valor de su propiedad `color`.
-## 📝 Instrucciones:
+## 📝 Instrucciones:
-1. Por favor, añade la posibilidad de especificar el color **green** (verde).
+1. Por favor, añade la posibilidad de especificar el color **green**.
-## Resultado esperado:
+## 💻 Resultado esperado:
-Tu sitio web deber terminar viéndose como este:
+Tu sitio web debe terminar viéndose como este:
-![3 Color Alert](../../.learn/assets/04.2-1.png?raw=true)
\ No newline at end of file
+![3 Color Alert](../../.learn/assets/04.2-1.png?raw=true)
diff --git a/exercises/04.2-conditional-rendering/README.md b/exercises/04.2-conditional-rendering/README.md
index 620fb9d5..fa5f9c69 100644
--- a/exercises/04.2-conditional-rendering/README.md
+++ b/exercises/04.2-conditional-rendering/README.md
@@ -4,13 +4,13 @@ tutorial: "https://www.youtube.com/watch?v=l3v6E1o_YUI"
# `04.2` Conditional Rendering
-Right now this `
` component can render in **orange** or **red** depending on the value of its `color` property.
+Right now, this `` component can render in **yellow** or **red** depending on the value of its `color` property.
## 📝 Instructions:
1. Please add the possibility to specify the color as **green**.
-## Expected result:
+## 💻 Expected result:
Your website must end up looking similar to this:
diff --git a/exercises/04.2-conditional-rendering/app.jsx b/exercises/04.2-conditional-rendering/app.jsx
index 2efc5543..6882a95d 100644
--- a/exercises/04.2-conditional-rendering/app.jsx
+++ b/exercises/04.2-conditional-rendering/app.jsx
@@ -2,12 +2,13 @@ import React from "react";
import ReactDOM from "react-dom";
import PropTypes from "prop-types";
-// add the green inside this function
+// Add the green inside this function
const Alert = props => {
const colorClasses = {
red: "alert-danger",
- orange: "alert-warning"
+ yellow: "alert-warning"
};
+
if (colorClasses[props.color] === undefined) alert(`The color ${props.color} is not in the possible list of colors`);
return (
@@ -21,12 +22,12 @@ Alert.propTypes = {
text: PropTypes.string
};
-// here is where the alert component is being used, you don't have to edit this part,
-// but it helps you understand what properties is the component using
+// Here is where the component is being used, you don't have to edit this part
+// But it helps you understand what properties is the component using
ReactDOM.render(
,
document.querySelector("#myDiv")
diff --git a/exercises/04.2-conditional-rendering/solution.hide.jsx b/exercises/04.2-conditional-rendering/solution.hide.jsx
new file mode 100644
index 00000000..9ad1d3d3
--- /dev/null
+++ b/exercises/04.2-conditional-rendering/solution.hide.jsx
@@ -0,0 +1,36 @@
+import React from "react";
+import ReactDOM from "react-dom";
+import PropTypes from "prop-types";
+
+// Add the green inside this function
+const Alert = props => {
+ const colorClasses = {
+ red: "alert-danger",
+ yellow: "alert-warning",
+ green: "alert-success"
+ };
+
+ if (colorClasses[props.color] === undefined) alert(`The color ${props.color} is not in the possible list of colors`);
+
+ return (
+
+ {props.text}
+
+ );
+};
+
+Alert.propTypes = {
+ color: PropTypes.string,
+ text: PropTypes.string
+};
+
+// Here is where the component is being used, you don't have to edit this part
+// But it helps you understand what properties is the component using
+ReactDOM.render(
+ ,
+ document.querySelector("#myDiv")
+);
diff --git a/exercises/04.2-conditional-rendering/tests.js b/exercises/04.2-conditional-rendering/tests.js
index daa3802b..b5db1000 100644
--- a/exercises/04.2-conditional-rendering/tests.js
+++ b/exercises/04.2-conditional-rendering/tests.js
@@ -17,7 +17,7 @@ test("The component Alert should return the exact HTML", () => {
className="alert alert-danger"
role="alert"
>
- OMG! Something really bad has happended!
+ OMG! Something really bad has happened!