Bruce Gust
asked on
How would I do this in a Javascript loop?
I have to write a program / function that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five, I've got to print "Buzz". For numbers which are multiples of both three and five, I've got to print "FizzBuzz".
How?
How?
Try this:
Hope it helps.
<html>
<body onload="doloop();">
<script language="javascript">
var c1,c2,r,o;
for (var i=1;i<=100;i++)
{
if (i%15==0) document.write('FizzBuzz<br />')
else if (i%5==0) document.write('Buzz<br />')
else if (i%3==0) document.wirte('Fizz<br />');
else document.write( i + '<br />');
}
</script>
</body>
</html>
Hope it helps.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Excellent!
Open in new window