FizzBu​​zz应用程序

FizzBu​​zz应用程序

本文介绍了Codecademy FizzBu​​zz应用程序,坚持第1步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是的代码

var i;
for ( i = 1; i > 20; i++ ) {
  "hello"
  if ( i % 3 === 0 ) {
    if ( i % 5 === 0 ) {
      "FizzBuzz";
    }
    else {
      "Fizz";
    }
  }
  else if ( i % 5 === 0 ) {
    "Buzz";
  }
 else {
    i;
  }
}

我正在尝试先测试是否数字(i)可被3整除。如果是,我想检查它是否也可以被5整除。如果两个条件都是真的,我希望它说FizzBu​​zz。如果只有第一个条件为真,那就应该说Fizz。然后,在确定i不能被3整除之后,它应该检查我是否可以被5整除并且如果是这样则显示Buzz。如果没有所有的可分性,它应该只显示数字。

I'm trying to first test whether or not the number (i) is divisible by 3. If it is, I then want to check whether it is also divisible by 5. If both conditions are true, I want it to say "FizzBuzz". If only the first condition is true, it should say "Fizz". Then, after determining that i is not divisible by 3, it should check whether i is divisible by 5 and show "Buzz" if that's the case. Failing all divisibility, it should just show the number.

正如我预期的那样...它没有按预期工作。我做了多么令人尴尬的错误?

As I expected... it doesn't work as expected. What terribly embarrassing mistakes have I made?

推荐答案

在考虑了所有其他非常好的答案之后:

After considering all the other very good answers here:

由于您使用您提供的代码坚持第1步,我认为您在点击链接并阅读说明后犯了同样的错误。第1步实际上并没有要求您解决Fizzbuzz问题。要通过这一步,您只需要做一些更简单的事情。再次阅读(不是很好)的说明;)

Since you're "stuck on step 1" with the code you've provided, I assume you did the same mistake I did after clicking your link and reading the instructions. Step 1 doesn't actually ask you to solve the Fizzbuzz problem. To pass this step, you only have to do something much simpler. Read the (not very good) instructions again ;)

这篇关于Codecademy FizzBu​​zz应用程序,坚持第1步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 16:26