Menu
CoddyTech

The FizzBuzz Function

Part of the Fundamentals section of Coddy's GDScript journey. Lesson 59 of 92.

challenge icon

Challenge

Easy

Keep 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" if number is 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:

  1. Read a whole number into a variable limit.
  2. Print the value fizzbuzz(limit) returns.

For the input 21, the output is:

Welcome to FizzBuzz!
FizzBuzz

Try it yourself

extends Node

func _ready():
	print("Welcome to FizzBuzz!")

All lessons in Fundamentals

Practice on your own: Online GDScript compiler