Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJohn Scully
1,018 PointsWhat is the point of using string interpolation in the buzzfizz example?
Hi,
I got this to work with the following:
for numbers in 1...50{
if numbers % 3 == 0 && numbers % 5 == 0 {
println("buzzfizz")
} else if numbers % 3 == 0 {
println("buzz")
} else if numbers % 5 == 0 {
println("fizz")
} else {
println (numbers)
}
}
My question is what the value is what the value of using string interpolation might be here?
1 Answer
jonroby
16,113 PointsYou aren't using string interpolation. You are just printing a string. An example of string interpolation is when you declare a variable, say a = "world". And then you print "Hello /(a)". This will output "Hello World".
John Scully
1,018 PointsJohn Scully
1,018 PointsThanks jonroby,
Sorry meant to say I got it to work without interpolation. I guess I'm just struggling to connect the dots as to why you might use interpolation for this example.
John Scully
1,018 PointsJohn Scully
1,018 PointsActually I thought about it a bit harder and realised how it can be useful to concatenate the buzz and fizz variables.
Thank you - your answer led me to realising why I might use it here.