freeCodeCamp/guide/chinese/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 根据数据更改样式

根据数据更改样式

再次什么是回调函数提醒自己

使用if-else逻辑或三元运算符可以通过两种方式完成此部分。

if-else逻辑

来自w3school的一个例子

```的JavaScript

const money = 50;

ifmoney <50{

回归“我富有”;

}

其他{

回归“我很穷”;

}

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的

条件值为true如果为false则为value

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

JavaScript的 .style“color”d=> { ifd <20{ 返回'红色' } 其他{ 返回'绿色' } } ```