fizzbuzz

Find if a number is divisible by 3 or 5 (FizzBuzz)

梦想的初衷 提交于 2019-12-05 21:53:33
How do I change the output depending on whether or not it is divisible by 3 or 5? If it is divisible by 3, I want to show "rock" and if it's divisible by 5 I want to show "star" (similar to in FizzBuzz). If both, they'll see both. Here's my code: if (var n = Math.floor((Math.random() * 1000) + 1); { var output = ""; if (n % 3 == 0) output += "Rock"; if (n % 5 == 0) output += "star"; prompt(output || n); } Why isn't my code working properly? var n = Math.floor((Math.random() * 1000) + 1); if (n) { var output = ""; if (n % 3 == 0) output += "Rock"; if (n % 5 == 0) output += "star"; prompt(output

Fizz Buzz in Ruby for dummies

折月煮酒 提交于 2019-12-04 16:20:52
Spoiler alert: I am a true novice. Tasked with figuring out fizz buzz in ruby for a class and while I have found more than a few versions of code that solve the problem, my understanding is so rudimentary that I cannot figure out how these examples truly work. First question(refer to spoiler alert if you laugh out loud at this): How do i print out numbers one through 100 in Ruby? Second question: can 'if else" be used to solve this? My failed code is below(attachment has screen shot): puts('Lets play fizzbuzz') print('enter a number: ') number = gets() puts(number) if number == % 3 puts ('fizz

How to reduce if statements [closed]

妖精的绣舞 提交于 2019-12-04 08:17:06
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . The program below functions as necessary but how do I reduce the amount of if statements. I have been told that if your function contains 2 or more if statements then your doing it wrong. Any suggestions? I've tried using switch statements but that hasn't worked because the case can't be a boolean. for(int i = 1

Python FizzBuzz

女生的网名这么多〃 提交于 2019-12-04 02:42:50
问题 I have been given this question to do in Python: Take in a list of numbers from the user and run FizzBuzz on that list. When you loop through the list remember the rules: 1) If the number is divisible by both 3 and 5 print FizzBuzz 2) If it's only divisible by 3 print Fizz 3) If it's only divisible by 5 print Buzz 4) Otherwise just print the number Also remember elif! I have the following script created, but it gives me an error at if n%3=True n=input() if n%3=True: print("Fizz") else if n%5

PHP FizzBuzz Logic

别说谁变了你拦得住时间么 提交于 2019-12-04 02:09:36
问题 When we write the fizzbuzz script, why are we testing to see if it is equal to 0? Or am I misunderstanding? Example: $i % 3 == 0 <?php for ($i=1; $i<=100; $i++) { if ($i%3==0 && $i%5==0) { echo 'FizzBuzz'; }else if($i%3==0){ echo 'Fizz'; }else if($i%5==0){ echo 'Buzz'; }else{ echo $i; } echo "\n"; } 回答1: The program fizzbuzz prints 'fizz' if a number is divisible by 3, 'buzz' if a number is divisible by 5, and 'fizzbuzz' if a number is divisible by both. Your program is not checking if the

How to code Fizzbuzz in F#

落花浮王杯 提交于 2019-12-03 06:47:39
问题 I am currently learning F# and have tried (an extremely) simple example of FizzBuzz. This is my initial attempt: for x in 1..100 do if x % 3 = 0 && x % 5 = 0 then printfn "FizzBuzz" elif x % 3 = 0 then printfn "Fizz" elif x % 5 = 0 then printfn "Buzz" else printfn "%d" x What solutions could be more elegant/simple/better (explaining why) using F# to solve this problem? Note: The FizzBuzz problem is going through the numbers 1 to 100 and every multiple of 3 prints Fizz, every multiple of 5

How to reduce if statements [closed]

好久不见. 提交于 2019-12-02 22:07:33
Closed. This question is off-topic. It is not currently accepting answers. Learn more . Want to improve this question? Update the question so it's on-topic for Stack Overflow. The program below functions as necessary but how do I reduce the amount of if statements. I have been told that if your function contains 2 or more if statements then your doing it wrong. Any suggestions? I've tried using switch statements but that hasn't worked because the case can't be a boolean. for(int i = 1; i < 100; i++) { if(i % 10 == 3) { System.out.println("Fizz" + "(" + i + ") 3%10"); } if(i / 10 == 3) { System

understanding the fizz buzz in C# [closed]

别来无恙 提交于 2019-12-02 20:31:48
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . When solving "fizz-buzz" in C# using a "while" loop, I found out that first I should find the multiples of both 3 and 5 (multiples of

How to code Fizzbuzz in F#

人盡茶涼 提交于 2019-12-02 20:26:57
I am currently learning F# and have tried (an extremely) simple example of FizzBuzz. This is my initial attempt: for x in 1..100 do if x % 3 = 0 && x % 5 = 0 then printfn "FizzBuzz" elif x % 3 = 0 then printfn "Fizz" elif x % 5 = 0 then printfn "Buzz" else printfn "%d" x What solutions could be more elegant/simple/better (explaining why) using F# to solve this problem? Note: The FizzBuzz problem is going through the numbers 1 to 100 and every multiple of 3 prints Fizz, every multiple of 5 prints Buzz, every multiple of both 3 AND 5 prints FizzBuzz. Otherwise, simple the number is displayed.

FizzBuzz in assembly - segmentation fault

旧时模样 提交于 2019-12-02 13:33:49
I am trying to write FizzBuzz in Assembly and I am seeing segmentation fault all the time. So far I have determined that it is not my printing routines (because I have removed their contents and the problem persists) and the error hides somewhere in the main function. I was getting this output when I run the program: fizzSegmentation fault Leading me to believe that it's not the problem with using division and looking up the remainders. But I could be wrong, I haven't done Assembly in two years... SECTION .data global _start fizz: db "fizz", 4 buzz: db "buzz", 4 SECTION .bss counter: resb 1