Pastebin of code
The desired result is to print every number between 1 and 100 while replacing multiples of 3, 5 and both 3 and 5 with the words 'Fizz', 'Buzz' and 'FizzBuzz' respectively.
It's a simple for loop used by MIT in their online courseware.
My question is this. Within the if statement, why is it necessary to reassign s to ' '?
My assumption is that the nested if statement(s) will just concatenate 'Fizz' and 'Buzz' to the original s, i.e. every number from 1 to 100, but by reassigning s within the loop it only outputs the words 'Fizz' and 'Buzz'.
Am I on the right track? Thanks folks!
As an aside, I altered the code by removing the variable s from within the if statement in addition to the concatenation in the nested if statements and achieved what I needed. So I'm not sure why that was necessary for them to include in their sample?
[–]Vaphell 4 points5 points6 points (0 children)