freeCodeCamp/guide/spanish/certifications/data-visualization/data-visualization-with-d3/change-styles-based-on-data/index.md

1.3 KiB
Raw Blame History

title localeTitle
Change Styles Based on Data Cambiar estilos basados en datos

Cambiar estilos basados en datos

Recuérdese una vez más cuál es la función de devolución de llamada con esto

Hay dos formas de completar esta parte, ya sea con la lógica if-else o con el operador ternario.

si-si la lógica

Un ejemplo de w3school

`` `javascript

dinero const = 50;

si (dinero <50) {

volver "Soy rico";

}

else {

volver "yo soy pobre";

}

What you need to remember is the bracket that the if-else logic associate with, (argument) and {statement} 
 
 **Try Yourself Now**  👩‍💻👨‍💻 
 
 
 
 **Ternary operator** 
 
 A more detailed explanation [here](https://codeburst.io/javascript-the-conditional-ternary-operator-explained-cac7218beeff). Ternary operator is a lot more concise and quicker to remember for a simple true or false statement. Read [this](https://www.thoughtco.com/javascript-by-example-use-of-the-ternary-operator-2037394) 

javascript

condición? valor si es verdadero: valor si es falso

For someone who still not sure here is a solution by using If-else statement 

javascript .style ("color", (d) => { si (d <20) { devuelve 'rojo' } else { volver 'verde' } }) `` `