fizzbuzz

Codecademy FizzBuzz app, stuck on step 1

狂风中的少年 提交于 2019-11-29 12:13:59
Here's my code for Codecamedy's FizzBuzz lesson 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'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

Swift 2: expression pattern of type 'Bool' cannot match values of type 'Int'

白昼怎懂夜的黑 提交于 2019-11-28 23:52:54
I'm doing this problem set "FizzBuzz", and my switch statement is giving me some problems, here's my code: func fizzBuzz(n: Int) -> String { switch n { case n % 3 == 0: print("Fizz") case n % 5 == 0: print("Buzz") case n % 15 == 0:print("FizzBuzz") } return "\(n)" } If you could provide me with pointers / hints, instead of giving me the correct code, that would be swell :D I'd prefer solving it myself, but a few hints could get me out of this hole. Try using "case let where": func fizzBuzz(n: Int) -> String { let result: String switch n { case let n where n % 3 == 0 && n % 5 == 0: result =

From 1 to 100, print “ping” if multiple of 3, “pong” if multiple of 5, or else print the number

假如想象 提交于 2019-11-28 19:22:05
问题 I just came home from a job interview, and the interviewer asked me to write a program: It should, count from 1 to 100, and print... If it was multiple of 3, "ping" If it was multiple of 5, "pong" Else, print the number. If it was multiple of 3 AND 5 (like 15), it should print "ping" and "pong". I chose Javascript, and came up with this: for (x=1; x <= 100; x++){ if( x % 3 == 0 ){ write("ping") } if( x % 5 == 0 ){ write("pong") } if( ( x % 3 != 0 ) && ( x % 5 != 0 ) ){ write(x) } } Actualy, I

FizzBuzz program (details given) in Javascript

a 夏天 提交于 2019-11-27 19:55:29
Can someone please correct this code of mine for FizzBuzz ? There seems to be a small mistake. This code below prints all the numbers instead of printing only numbers that are not divisible by 3 or 5. Write a program that prints the numbers from 1 to 100 . But for multiples of three, print "Fizz" instead of the number, and for the multiples of five, print "Buzz" . For numbers which are multiples of both three and five, print "FizzBuzz" . function isDivisible(numa, num) { if (numa % num == 0) { return true; } else { return false; } }; function by3(num) { if (isDivisible(num, 3)) { console.log(

Swift 2: expression pattern of type 'Bool' cannot match values of type 'Int'

喜夏-厌秋 提交于 2019-11-26 23:04:16
问题 I'm doing this problem set "FizzBuzz", and my switch statement is giving me some problems, here's my code: func fizzBuzz(n: Int) -> String { switch n { case n % 3 == 0: print("Fizz") case n % 5 == 0: print("Buzz") case n % 15 == 0:print("FizzBuzz") } return "\(n)" } If you could provide me with pointers / hints, instead of giving me the correct code, that would be swell :D I'd prefer solving it myself, but a few hints could get me out of this hole. 回答1: You can use case let where and check if