The FizzBuzz Function
Part of the Fundamentals section of Coddy's GDScript journey. Lesson 59 of 92.
Challenge
EasyKeep the welcome message from the previous step.
Below _ready(), add a function fizzbuzz with one int parameter, number, and the return type String. It returns:
"FizzBuzz"ifnumberis divisible by both 3 and 7"Fizz"if it is divisible by 3"Buzz"if it is divisible by 7- otherwise, the number itself as a
String, for example"5"
Then, in _ready(), after the welcome message:
- Read a whole number into a variable
limit. - Print the value
fizzbuzz(limit)returns.
For the input 21, the output is:
Welcome to FizzBuzz!
FizzBuzzTry it yourself
extends Node
func _ready():
print("Welcome to FizzBuzz!")
All lessons in Fundamentals
4Operators Part 1
Arithmetic OperatorsInteger DivisionModulo OperatorArithmetic ShortcutsRecap - Simple MathComparison Operators10Functions
Declare a FunctionArgumentsReturnReturn TypesRecap - Sigma FunctionRecap - Validation FunctionDefault Values5Operators Part 2
Logical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 3Ternary OperatorPractice on your own: Online GDScript compiler