front-end-interview-handbook/packages/quiz/questions/create-a-for-loop-that-iter.../zh-CN.mdx

16 lines
623 B
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: 创建一个for循环迭代到`100`,同时在`3`的倍数上输出**"fizz "**,在`5`的倍数上输出**"buzz"**,在`3`和`5`的公倍数上输出**"fizzbuzz"**。
---
看看这个版本的 FizzBuzz作者是 [Paul Irish](https://gist.github.com/jaysonrowe/1592432#gistcomment-790724)。
```js
for (let i = 1; i <= 100; i++) {
let f = i % 3 == 0,
b = i % 5 == 0;
console.log(f ? (b ? 'FizzBuzz' : 'Fizz') : b ? 'Buzz' : i);
}
```
不过,上述内容不宜在面试时写。 只要坚持长期而明确的做法。 关于更多古怪的 FizzBuzz 版本,请查看下面的参考链接。