Your task is to write a Rust program that implements the classic programming challenge known as FizzBuzz.
You are given a function fizz_buzz(num: u32) -> String
that takes a single parameter num
of type u32
and returns a String
.
Your job is to return a string based on the following rules:
Here's how the behavior of the function should look like:
Good luck, and happy coding!
CB-42458
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge let three_is_factor: bool = num % 3 == 0; let five_is_factor: bool = num % 5 == 0; match (three_is_factor, five_is_factor) { (false, false) => num.to_string(), (true, false) => String::from("Fizz"), (false, true) => String::from("Buzz"), (true, true) => String::from("FizzBuzz"), }}
quantumxt
pub fn fizz_buzz(num: u32) -> String { if num % 3 == 0 && num % 5 == 0 { String::from("FizzBuzz") } else if num % 3 == 0 { String::from("Fizz") } else if num % 5 == 0 { String::from("Buzz") } else { num.to_string() }}
GideonBature
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge if num % 3 == 0 && num % 5 == 0 { String::from("FizzBuzz") } else if num % 3 == 0 { String::from("Fizz") } else if num % 5 == 0 { String::from("Buzz") } else { num.to_string() }}
herlock77
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge match num { _ if num%3 == 0 => if num%5 != 0 { "Fizz".to_string() } else {"FizzBuzz".to_string()}, _ if num%5 == 0 => "Buzz".to_string(), _=> num.to_string(), } }
enzo-rma
pub fn fizz_buzz(num: u32) -> String { if num % 3 == 0 && num % 5 == 0 { return String::from("FizzBuzz"); } else if num % 3 == 0 { return String::from("Fizz"); } else if num % 5 == 0 { return String::from("Buzz"); } else { return num.to_string(); }}
Squirkyy
pub fn fizz_buzz(num: u32) -> String { if num % 3 == 0 && num % 5 == 0 { return String::from("FizzBuzz"); } else if num % 5 == 0 { return String::from("Buzz"); } else if num % 3 == 0 { return String::from("Fizz"); } else { return num.to_string(); }}
Squirkyy
pub fn fizz_buzz(num: u32) -> String { if num % 3 == 0 && num % 5 == 0 { return String::from("FizzBuzz"); } else if num % 5 == 0 { return String::from("Buzz"); } else if num % 3 == 0 { return String::from("Fizz"); } else { return num.to_string(); }}
anojht
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge if num % 3 == 0 && num % 5 == 0 { return String::from("FizzBuzz"); } else if num % 3 == 0 { return String::from("Fizz"); } else if num % 5 == 0 { return String::from("Buzz"); } else { return String::from("{num}"); }}
Bethel-nz
pub fn fizz_buzz(num: u32) -> String { match (num % 3 == 0, num % 5 == 0) { (true, true) => String::from("FizzBuzz"), (true, false) => String::from("Fizz"), (false, true) => String::from("Buzz"), (false, false) => num.to_string(), }}
Bethel-nz
pub fn fizz_buzz(num: u32) -> String { match (num % 3 == 0, num % 5 == 0) { (true, true) => String::from("FizzBuzz"), (true, false) => String::from("Fizz"), (false, true) => String::from("Buzz"), (false, false) => num.to_string(), }}
BlakeEric
pub fn fizz_buzz(num: u32) -> String { // If the number is divisible by 3, return "Fizz" // If the number is divisible by 5, return "Buzz" // If the number is divisible by 3 and 5, return "FizzBuzz" fn is_three(num: u32) -> bool { println!("{}", num % 3); return num % 3 == 0 } fn is_five(num: u32) -> bool { println!("hello there!"); return num % 5 == 0 } if is_three(num) && is_five(num) { return "FizzBuzz".to_string(); } else if is_three(num) { return "Fizz".to_string(); }else if is_five(num) { return "Buzz".to_string(); } return num.to_string();}
poeck
pub fn fizz_buzz(num: u32) -> String { if num % 3 == 0 && num % 5 == 0 { return "FizzBuzz".to_string(); } else if num % 3 == 0 { return "Fizz".to_string(); } else if num % 5 == 0 { return "Buzz".to_string(); } else { return num.to_string(); }}
MrSingh2000
pub fn fizz_buzz(num: u32) -> String { // If the number is divisible by 3, return "Fizz" // If the number is divisible by 5, return "Buzz" // If the number is divisible by 3 and 5, return "FizzBuzz" match (num % 3, num % 5){ (0,0) => String::from("FizzBuzz"), (0,_) => String::from("Fizz"), (_, 0) => String::from("Buzz"), _ => num.to_string(), }}
foxy4096
pub fn fizz_buzz(num: u32) -> String { // If the number is divisible by 3, return "Fizz" // If the number is divisible by 5, return "Buzz" // If the number is divisible by 3 and 5, return "FizzBuzz" if num % 3 == 0 && num % 5 != 0 { return "Fizz".to_string(); } else if num % 3 != 0 && num % 5 == 0 { return "Buzz".to_string(); } else if num % 3 == 0 && num % 5 == 0 { return "FizzBuzz".to_string(); } else { return num.to_string(); }}
dcodes
pub fn fizz_buzz(num: u32) -> String { // If the number is divisible by 3, return "Fizz" // If the number is divisible by 5, return "Buzz" // If the number is divisible by 3 and 5, return "FizzBuzz" match (num % 3 == 0, num % 5 == 0) { (true, false) => "Fizz".to_string(), (false, true) => "Buzz".to_string(), (true, true) => "FizzBuzz".to_string(), _ => num.to_string() }}